結果

問題 No.2329 Nafmo、イカサマをする
ユーザー tnakao0123tnakao0123
提出日時 2023-06-26 18:53:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,847 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 59,172 KB
実行使用メモリ 12,532 KB
最終ジャッジ日時 2023-09-16 13:21:30
合計ジャッジ時間 3,422 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 17 ms
4,700 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 20 ms
4,708 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 39 ms
7,288 KB
testcase_37 AC 15 ms
4,664 KB
testcase_38 AC 2 ms
4,384 KB
testcase_39 AC 81 ms
11,688 KB
testcase_40 AC 81 ms
12,520 KB
testcase_41 AC 85 ms
12,532 KB
testcase_42 AC 81 ms
11,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2329.cc:  No.2329 Nafmo、イカサマをする - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_K = 6;

/* typedef */

typedef long long ll;
typedef vector<ll> vl;

/* global variables */

int as[MAX_N];
vl svs[MAX_K + 1];

/* subroutines */

/* main */

int main() {
  int n, k;
  ll m;
  scanf("%d%lld%d", &n, &m, &k);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as, as + n);
  n = unique(as, as + n) - as;

  ll maxc = 0;
  if (k >= 1) {
    vl &sv1 = svs[1];
    for (int i0 = 0; i0 < n; i0++) sv1.push_back(as[i0]);
    auto vit = upper_bound(sv1.begin(), sv1.end(), m);
    if (vit != sv1.begin()) maxc = max(maxc, *(vit - 1));
  }
  if (k >= 2) {
    vl &sv2 = svs[2];
    for (int i0 = 0; i0 < n; i0++)
      for (int i1 = 0; i1 < n; i1++)
	sv2.push_back((ll)as[i0] + as[i1]);
    sort(sv2.begin(), sv2.end());
    sv2.erase(unique(sv2.begin(), sv2.end()), sv2.end());
    auto vit = upper_bound(sv2.begin(), sv2.end(), m);
    if (vit != sv2.begin()) maxc = max(maxc, *(vit - 1));
  }
  if (k >= 3) {
    vl &sv3 = svs[3];
    for (int i0 = 0; i0 < n; i0++)
      for (int i1 = 0; i1 < n; i1++)
	for (int i2 = 0; i2 < n; i2++)
	  sv3.push_back((ll)as[i0] + as[i1] + as[i2]);
    sort(sv3.begin(), sv3.end());
    sv3.erase(unique(sv3.begin(), sv3.end()), sv3.end());
    auto vit = upper_bound(sv3.begin(), sv3.end(), m);
    if (vit != sv3.begin()) maxc = max(maxc, *(vit - 1));
  }

  for (int i = 1; i <= 3 && i + 3 <= k; i++) {
    vl &svi = svs[i], &sv3 = svs[3];
    for (auto u: svi) {
      if (u > m) break;
      auto vit = upper_bound(sv3.begin(), sv3.end(), m - u);
      if (vit != sv3.begin()) maxc = max(maxc, u + *(vit - 1));
    }
  }

  printf("%lld\n", maxc);
  return 0;
}
0