結果

問題 No.2730 Two Types Luggage
ユーザー tnakao0123
提出日時 2024-04-30 16:08:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 1,204 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 66,132 KB
最終ジャッジ日時 2025-02-21 09:53:57
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |   scanf("%d%d%lld", &n, &m, &w);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:35:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |   for (int i = 0; i < n; i++) scanf("%d", as + i);
      |                               ~~~~~^~~~~~~~~~~~~~
main.cpp:36:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   for (int i = 0; i < m; i++) scanf("%d", bs + i);
      |                               ~~~~~^~~~~~~~~~~~~~
main.cpp:37:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   for (int i = 0; i < m; i++) scanf("%d", cs + i);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2730.cc:  No.2730 Two Types Luggage - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000000;
const int MAX_M = 20;
const int MBITS = 1 << MAX_M;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], bs[MAX_M], cs[MAX_M];
ll ass[MAX_N + 1], bss[MBITS], css[MBITS];

/* subroutines */

/* main */

int main() {
  int n, m;
  ll w;
  scanf("%d%d%lld", &n, &m, &w);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < m; i++) scanf("%d", bs + i);
  for (int i = 0; i < m; i++) scanf("%d", cs + i);

  sort(as, as + n, greater<int>());
  for (int i = 0; i < n; i++) ass[i + 1] = ass[i] + as[i];

  int mbits = 1 << m;
  for (int bits = 1, msb = 1, msi = 0; bits < mbits; bits++) {
    if ((msb << 1) <= bits) msb <<= 1, msi++;
    bss[bits] = bss[bits ^ msb] + bs[msi];
    css[bits] = css[bits ^ msb] + cs[msi];
  }

  ll maxc = 0;
  for (int bits = 0; bits < mbits; bits++) {
    ll dw = w - bss[bits];
    if (dw >= 0) {
      ll c = css[bits] + ass[min((ll)n, dw)];
      maxc = max(maxc, c);
    }
  }

  printf("%lld\n", maxc);

  return 0;
}
0