結果

問題 No.1007 コイン集め
ユーザー ateate
提出日時 2020-07-08 22:28:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 524 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 76,000 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:17:37
合計ジャッジ時間 1,955 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
signed main(){
  int n,k;
  std::cin>>n>>k;
  k--;
  std::vector<int> a(n);
  for(auto& ai:a)std::cin>>ai;
  int l=k,r=k;
  while(l>0){
    if(a[l]<=1)break;
    l--;
  }
  while(r<n){
    if(a[r]<=1)break;
    r++;
  }
  if(a[k]==1){
    int64_t suml=0,sumr=0;
    for(int i=k;i>=l;--i)suml+=a[i];
    for(int i=k;i<=r;++i)sumr+=a[i];
    std::cout<< std::max(suml,sumr) <<std::endl;
    return 0;
  }
  int64_t ans = 0;
  for(int i=l;i<=r;++i)ans+=a[i];
  std::cout<< ans <<std::endl;
}
0