結果

問題 No.1007 コイン集め
ユーザー ei1333333ei1333333
提出日時 2017-06-24 00:52:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 46 ms / 1,500 ms
コード長 612 bytes
コンパイル時間 1,455 ms
コンパイル使用メモリ 159,556 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 06:51:57
合計ジャッジ時間 3,382 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,948 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 42 ms
6,944 KB
testcase_13 AC 42 ms
6,944 KB
testcase_14 AC 42 ms
6,940 KB
testcase_15 AC 18 ms
6,944 KB
testcase_16 AC 17 ms
6,940 KB
testcase_17 AC 18 ms
6,944 KB
testcase_18 AC 46 ms
6,940 KB
testcase_19 AC 45 ms
6,940 KB
testcase_20 AC 45 ms
6,944 KB
testcase_21 AC 45 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
  int N, K, A[200000];

  cin >> N >> K;
  --K;
  for(int i = 0; i < N; i++) cin >> A[i];

  int left = 0, right = N - 1;
  for(int i = 0; i < N; i++) {
    if(i < K && A[i] <= 1) left = max(left, i);
    if(i > K && A[i] <= 1) right = min(right, i);
  }

  ll aaa = 0, bbb = 0;
  for(int i = left; i <= K; i++) aaa += A[i];
  for(int i = right; i >= K; i--) bbb += A[i];

  if(A[K] == 0) {
    cout << 0 << endl;
  } else if(A[K] == 1) {
    cout << max(aaa, bbb) << endl;
  } else {
    cout << aaa + bbb - A[K] << endl;
  }
}
0