結果
問題 |
No.2329 Nafmo、イカサマをする
|
ユーザー |
|
提出日時 | 2023-04-28 15:25:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 99 ms / 2,000 ms |
コード長 | 1,193 bytes |
コンパイル時間 | 2,218 ms |
コンパイル使用メモリ | 201,952 KB |
最終ジャッジ日時 | 2025-02-12 14:42:28 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include<bits/stdc++.h> typedef long long int ll; using namespace std; int main() { ll N, M, K, ans = 0; cin >> N >> M >> K; vector<ll> A(N + 1); set<ll> sum, sum2; for (int i = 0; i < N; i++) cin >> A[i]; A[N] = 0; if (K == 1) { for (int i = 0; i < N + 1; i++) sum.insert(A[i]); } if (K == 2 || K == 4 || K == 5) { for (int i = 0; i < N + 1; i++) { for (int j = 0; j < N + 1; j++) { if (A[i] + A[j] <= M) { if (K != 5) sum.insert(A[i] + A[j]); else sum2.insert(A[i] + A[j]); } } } } if (K == 3 || K == 6 || K == 5) { for (int i = 0; i < N + 1; i++) { for (int j = 0; j < N + 1; j++) { for (int k = 0; k < N + 1; k++) { if (A[i] + A[j] + A[k] <= M) { sum.insert(A[i] + A[j] + A[k]); } } } } } if (K <= 3) { auto it = --sum.upper_bound(M); ans = ( * it); } else if (K != 5) { for (auto x: sum) { auto it = --sum.upper_bound(M - x); ans = max(x + ( * it), ans); } } else { for (auto x: sum2) { auto it = --sum.upper_bound(M - x); ans = max(x + ( * it), ans); } } cout << ans << endl; }