結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    k--;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    if (a[k] == 0) {
        cout << 0 << endl;
        exit(0);
    }

    ll r = a[k];
    ll t[2] = {};
    for (int i = k + 1; i < n; i++) {
        t[0] += a[i];
        if (a[i] < 2) break;
    }
    for (int i = k - 1; i >= 0; i--) {
        t[1] += a[i];
        if (a[i] < 2) break;
    }
    if (a[k] >= 2) {
        r += t[0] + t[1];
    } else {
        r += max(t[0], t[1]);
    }

    cout << r << endl;

    return 0;
}
0