結果

問題 No.2329 Nafmo、イカサマをする
ユーザー shobonvipshobonvip
提出日時 2023-05-28 14:51:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 1,215 bytes
コンパイル時間 5,081 ms
コンパイル使用メモリ 263,352 KB
実行使用メモリ 24,524 KB
最終ジャッジ日時 2023-08-27 10:44:47
合計ジャッジ時間 6,842 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 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 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,504 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 25 ms
5,100 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 28 ms
5,212 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 12 ms
4,444 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 122 ms
13,956 KB
testcase_37 AC 21 ms
5,172 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 122 ms
12,660 KB
testcase_40 AC 127 ms
11,824 KB
testcase_41 AC 261 ms
24,524 KB
testcase_42 AC 122 ms
11,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

// importbisect
template <typename T>
int bisect_left(vector<T> &X, T v){
	return lower_bound(X.begin(), X.end(), v) - X.begin();
}

template <typename T>
int bisect_right(vector<T> &X, T v){
	return upper_bound(X.begin(), X.end(), v) - X.begin();
}
// -----


vector<ll> ju(int n, vector<ll> &a, int k){
	if (k <= 0) return {0};
	vector<ll> ret = ju(n, a, k-1);
	for (int i=0; i<n; i++){
		if (k > 1){
			vector<ll> tmp = ju(n, a, k-1);
			for (int j=0; j<(int)tmp.size(); j++){
				ret.push_back(a[i] + tmp[j]);
			}
		}else{
			ret.push_back(a[i]);
		}
	}
	sort(ret.begin(), ret.end());
	return ret;
}

int main(){
	int n; ll m; int k; cin >> n >> m >> k;
	vector<ll> a(n);
	for (int i=0; i<n; i++){
		cin >> a[i];
	}
	
	if (k <= 3){
		vector<ll> ret = ju(n, a, k);
		int f = bisect_right(ret, m) - 1;
		cout << ret[f] << endl;
	}else{
		vector<ll> ret1 = ju(n, a, 3);
		vector<ll> ret2 = ju(n, a, k-3);
		ll ans = 0;
		for (ll t: ret2){
			int f = bisect_right(ret1, m - t) - 1;
			if (f >= 0){
				ans = max(ans, ret1[f] + t);
			}
		}
		cout << ans << endl;
	}
}
0