結果
| 問題 |
No.1007 コイン集め
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-21 22:42:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 681 bytes |
| コンパイル時間 | 1,546 ms |
| コンパイル使用メモリ | 168,592 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-22 22:54:01 |
| 合計ジャッジ時間 | 2,729 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
int main() {
int n, k;
cin >> n >> k;
vector<ll> a(n+2);
rep(i,n) cin >> a[i+1];
if (a[k] == 0) {
cout << 0 << endl;
return 0;
}
int l = k-1, r = k+1;
while (l >= 0 && a[l] > 1) {
l--;
}
while (r < n && a[r] > 1) {
r++;
}
ll ans = 0;
if (a[k] >= 2) {
for (int i = l; i <= r; i++) ans += a[i];
} else {
int cand1 = 0, cand2 = 0;
for (int i = l; i <= k; i++) cand1 += a[i];
for (int i = k; i <= r; i++) cand2 += a[i];
ans = max(cand1, cand2);
}
cout << ans << endl;
}