結果

問題 No.1007 コイン集め
ユーザー rogi52rogi52
提出日時 2022-10-04 23:58:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 763 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 196,392 KB
最終ジャッジ日時 2025-02-07 21:38:25
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 8 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,K; cin >> N >> K; K--;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    if(A[K] == 0) {
        cout << 0 << endl;
    } else {
        int L = N - 1, R = 0;
        rep(i,N) {
            if(A[i] < 2) {
                L = min(L, i);
                R = max(R, i);
            }
        }

        ll sumL = 0, sumR = 0;
        for(int i = L; i <= K; i++) sumL += A[i];
        for(int i = K; i <= R; i++) sumR += A[i];
        if(A[K] == 1) {
            cout << max(sumL, sumR) << endl;
        } else {
            cout << sumL + sumR - A[K] << endl;
        }
    }
}
0