結果
問題 | No.2329 Nafmo、イカサマをする |
ユーザー | rurun |
提出日時 | 2023-05-28 15:05:10 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 138 ms / 2,000 ms |
コード長 | 2,017 bytes |
コンパイル時間 | 2,048 ms |
コンパイル使用メモリ | 207,188 KB |
実行使用メモリ | 19,300 KB |
最終ジャッジ日時 | 2023-08-27 11:21:50 |
合計ジャッジ時間 | 4,448 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 2 ms
4,376 KB |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 4 ms
4,380 KB |
testcase_19 | AC | 25 ms
6,284 KB |
testcase_20 | AC | 9 ms
4,380 KB |
testcase_21 | AC | 30 ms
6,944 KB |
testcase_22 | AC | 4 ms
4,380 KB |
testcase_23 | AC | 32 ms
7,512 KB |
testcase_24 | AC | 12 ms
4,560 KB |
testcase_25 | AC | 6 ms
4,376 KB |
testcase_26 | AC | 9 ms
4,400 KB |
testcase_27 | AC | 8 ms
4,376 KB |
testcase_28 | AC | 4 ms
4,376 KB |
testcase_29 | AC | 8 ms
4,376 KB |
testcase_30 | AC | 4 ms
4,380 KB |
testcase_31 | AC | 37 ms
8,244 KB |
testcase_32 | AC | 2 ms
4,380 KB |
testcase_33 | AC | 8 ms
4,380 KB |
testcase_34 | AC | 12 ms
4,612 KB |
testcase_35 | AC | 3 ms
4,376 KB |
testcase_36 | AC | 63 ms
10,916 KB |
testcase_37 | AC | 20 ms
5,928 KB |
testcase_38 | AC | 119 ms
18,992 KB |
testcase_39 | AC | 136 ms
19,300 KB |
testcase_40 | AC | 126 ms
19,008 KB |
testcase_41 | AC | 138 ms
19,176 KB |
testcase_42 | AC | 125 ms
18,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; int main() { lint n, m, k; cin >> n >> m >> k; vector<lint> a(n); for (int i = 0; i < n; i++) cin >> a[i]; a.push_back(0); n++; vector<lint> vec3(n*n*n); vector<lint> vec2(n*n*n); int cnt = 0; int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { vec3[cnt] = a[i]+a[j]+a[k]; cnt++; } vec2[count] = a[i]+a[j]; count++; } } sort(vec3.begin(), vec3.end()); sort(vec2.begin(), vec2.end()); sort(a.begin(), a.end()); lint ans = -1; if (k == 1) { auto itr = upper_bound(a.begin(), a.end(), m); int idx = itr-a.begin()-1; ans = a[idx]; } else if (k == 2) { auto itr = upper_bound(vec2.begin(), vec2.end(), m); int idx = itr-vec2.begin()-1; ans = vec2[idx]; } else if (k == 3) { auto itr = upper_bound(vec3.begin(), vec3.end(), m); int idx = itr-vec3.begin()-1; ans = vec3[idx]; } else if (k == 4) { for (int i = 0; i < n*n*n; i++) { auto itr = upper_bound(a.begin(), a.end(), m-vec3[i]); if (itr == a.begin()) continue; else { int idx = itr-a.begin()-1; if (vec3[i]+a[idx] > m) continue; else ans = max(ans, vec3[i]+a[idx]); } } } else if (k == 5) { for (int i = 0; i < n*n*n; i++) { auto itr = upper_bound(vec2.begin(), vec2.end(), m-vec3[i]); if (itr == vec2.begin()) continue; else { int idx = itr-vec2.begin()-1; if (vec3[i]+vec2[idx] > m) continue; else ans = max(ans, vec3[i]+vec2[idx]); } } } else if (k == 6) { for (int i = 0; i < n*n*n; i++) { auto itr = upper_bound(vec3.begin(), vec3.end(), m-vec3[i]); if (itr == vec3.begin()) continue; else { int idx = itr-vec3.begin()-1; if (vec3[i]+vec3[idx] > m) continue; else ans = max(ans, vec3[i]+vec3[idx]); } } } cout << ans << endl; }