結果
| 問題 |
No.2329 Nafmo、イカサマをする
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-28 15:59:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,335 bytes |
| コンパイル時間 | 2,719 ms |
| コンパイル使用メモリ | 201,468 KB |
| 最終ジャッジ日時 | 2025-02-13 14:55:20 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 WA * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n + 1);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
n++;
vector<int> a2;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a2.push_back(a[i] + a[j]);
}
}
sort(a2.begin(), a2.end());
vector<int> a3;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int jj = 0; jj < n; jj++) {
a3.push_back(a[i] + a[j] + a[jj]);
}
}
}
sort(a3.begin(), a3.end());
n++;
if (k == 1) {
cout << *prev(upper_bound(a.begin(), a.end(), m)) << endl;
}
if (k == 2) {
cout << *prev(upper_bound(a2.begin(), a2.end(), m)) << endl;
}
if (k == 3) {
int ans = 0;
for (int i = 0; i < a.size(); i++) {
if (a[i] > m) {
continue;
}
auto key = m - a[i];
auto it = prev(upper_bound(a2.begin(), a2.end(), key));
chmax(ans, a[i] + *it);
}
cout << ans << endl;
}
if (k == 4) {
int ans = 0;
for (int i = 0; i < a2.size(); i++) {
if (a2[i] > m) {
continue;
}
auto key = m - a2[i];
auto it = prev(upper_bound(a2.begin(), a2.end(), key));
chmax(ans, a2[i] + *it);
}
cout << ans << endl;
}
if (k == 5) {
int ans = 0;
for (int i = 0; i < a2.size(); i++) {
if (a2[i] > m) {
continue;
}
auto key = m - a2[i];
auto it = prev(upper_bound(a3.begin(), a3.end(), key));
chmax(ans, a2[i] + *it);
}
cout << ans << endl;
}
if (k == 6) {
int ans = 0;
for (int i = 0; i < a3.size(); i++) {
if (a3[i] > m) {
continue;
}
auto key = m - a3[i];
auto it = prev(upper_bound(a3.begin(), a3.end(), key));
chmax(ans, a3[i] + *it);
}
cout << ans << endl;
}
return 0;
}