結果
| 問題 |
No.1007 コイン集め
|
| コンテスト | |
| ユーザー |
yuboolku
|
| 提出日時 | 2020-03-06 23:09:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 1,500 ms |
| コード長 | 1,171 bytes |
| コンパイル時間 | 1,565 ms |
| コンパイル使用メモリ | 166,548 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-14 09:38:07 |
| 合計ジャッジ時間 | 2,778 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
int main(){
int N, K;
cin >> N >> K;
int l = 0;
int r = N-1;
ll A[N];
rep(i, N) {
cin >> A[i];
if (A[i] <= 1 && i < K - 1) {
l = i;
} else if (A[i] <= 1 && i > K - 1 && r == N-1) {
r = i;
}
}
ll ans1 = 0;
ll ans2 = 0;
REP(i, l, K) {
ans1 += A[i];
}
REP(i, K, r+1) {
ans2 += A[i];
}
// cout << ans1 << " " << ans2 << endl;
if (A[K - 1] == 0) {
cout << 0 << endl;
} else if (A[K - 1] == 1) {
cout << max(ans1 , ans2+1) << endl;
} else {
cout << ans1 + ans2 << endl;
}
}
yuboolku