結果
問題 |
No.2028 Even Choice
|
ユーザー |
|
提出日時 | 2022-08-05 23:02:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,163 bytes |
コンパイル時間 | 1,898 ms |
コンパイル使用メモリ | 177,872 KB |
実行使用メモリ | 14,080 KB |
最終ジャッジ日時 | 2024-09-15 20:32:55 |
合計ジャッジ時間 | 4,384 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<PII> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i].first; a[i].second = i; } a[1] = {0, 1}; sort(a.begin() + 1, a.end(), [&](PII a, PII b){ if (a.first != b.first) return a.first > b.first; return a.second < b.second; }); ll sum = 0; set<int> s; for (int i = 1; i <= k; i++) { sum += a[i].first; s.insert(a[i].second); } if (*s.begin() % 2 == 0) { cout << sum << '\n'; } else { auto it = next(s.begin()); int x = n + 1; if (it != s.end()) { x = *it; } int mx = 0; for (int i = 1; i <= n; i++) { if (a[i].second % 2 == 0 and a[i].second < x) { mx = max(mx, a[i].first); } if (a[i].second == *s.begin()) { sum -= a[i].first; } } sum += mx; cout << sum << '\n'; } return 0; }