結果
| 問題 |
No.1007 コイン集め
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-31 10:51:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,175 bytes |
| コンパイル時間 | 1,837 ms |
| コンパイル使用メモリ | 168,268 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-15 18:17:14 |
| 合計ジャッジ時間 | 3,236 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 11 |
ソースコード
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
K--;
vector<ll> A(N);
rep(i, N) { cin >> A[i]; }
bool judge = (A[K] >= 3 ? 1 : 0);
// right
ll right = K, rtmp = 0;
while (right < N) {
if (A[right] >= 2)
rtmp += A[right];
else if (A[right] == 1) {
rtmp += A[right];
break;
} else
break;
right++;
}
// left
ll left = K, ltmp = 0;
while (left > 0) {
if (A[left] >= 2)
ltmp += A[left];
else if (A[left] == 1) {
ltmp += A[left];
break;
} else
break;
left--;
}
if (judge && rtmp > 0 && ltmp > 0) {
cout << rtmp + ltmp - A[K] << endl;
} else if (judge) {
cout << rtmp + ltmp << endl;
} else
cout << max(rtmp, ltmp) << endl;
}