結果

問題 No.1007 コイン集め
ユーザー Aquarius
提出日時 2020-03-15 18:31:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 1,500 ms
コード長 676 bytes
コンパイル時間 1,406 ms
コンパイル使用メモリ 166,808 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 07:05:43
合計ジャッジ時間 2,977 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int N, P;
long A[200000];

long sub(int l, int r) {
    long sum = 0;
    for (int i = l; i < r; ++i) {
        sum += A[i];
    }
    return sum;
}

int main() {
    cin >> N >> P; --P;
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    int left = P - 1;
    while (left > 0 && A[left] >= 2) {
        --left;
    }
    
    int right = P + 1;
    while (right < N - 1 && A[right] >= 2) {
        ++right;
    }
    
    if (A[P] == 0) {
        cout << 0 << endl;
    } else if (A[P] == 1) {
        cout << max(sub(left, P + 1), sub(P, right + 1)) << endl;
    } else {
        cout << sub(left, right + 1) << endl;
    }
}
0