結果

問題 No.1007 コイン集め
ユーザー bonKotsubonKotsu
提出日時 2021-06-21 22:42:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 681 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 166,920 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 01:57:26
合計ジャッジ時間 2,991 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 40 ms
4,380 KB
testcase_13 AC 40 ms
4,376 KB
testcase_14 AC 40 ms
4,380 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 16 ms
4,380 KB
testcase_17 AC 16 ms
4,376 KB
testcase_18 AC 43 ms
4,380 KB
testcase_19 AC 42 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 43 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n+2);
  rep(i,n) cin >> a[i+1];
  
  if (a[k] == 0) {
    cout << 0 << endl;
    return 0;
  }

  int l = k-1, r = k+1;
  while (l >= 0 && a[l] > 1) {
    l--;
  }
  while (r < n && a[r] > 1) {
    r++;
  }
  ll ans = 0;
  if (a[k] >= 2) {
    for (int i = l; i <= r; i++) ans += a[i];
  } else {
    int cand1 = 0, cand2 = 0;
    for (int i = l; i <= k; i++) cand1 += a[i];
    for (int i = k; i <= r; i++) cand2 += a[i];
    ans = max(cand1, cand2);
  }
  cout << ans << endl;


}
0