結果
| 問題 |
No.1007 コイン集め
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-09 02:17:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,322 bytes |
| コンパイル時間 | 1,537 ms |
| コンパイル使用メモリ | 168,988 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 20:26:59 |
| 合計ジャッジ時間 | 2,782 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 5 |
ソースコード
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void){
int N,K;
cin >> N >> K;
vector<long> A(N);
vector<long> ASUM(N);
int startidx=0;
int endidx=N-1;
for(int i=0;i<N;i++){
if(i!=K-1){
long s;
cin >> s;
A.at(i)=s;
if(i==0){
ASUM.at(i)=s;
}else{
ASUM.at(i)=ASUM.at(i-1)+s;
}
if(s<=1&&i<K-1){
startidx=i;
}else if(s<=1&&i>K-1){
endidx=i;
}
}else{
cin >> A.at(i);
if(i>0){
ASUM.at(i)=ASUM.at(i-1)+A.at(i);
}else{
ASUM.at(i)=A.at(i);
}
}
}
if(A.at(K-1)==0){
cout << 0 << endl;
}else if(A.at(K-1)==1){
long ans1=ASUM.at(K-1)-ASUM.at(startidx);
if(startidx==0){
ans1+=ASUM.at(0);
}
long ans2=ASUM.at(endidx)-ASUM.at(K-1);
if(ans1<ans2){
cout << ans2 << endl;
}else{
cout << ans1 << endl;
}
}else{
if(startidx>0){
cout << ASUM.at(endidx)-ASUM.at(startidx-1) << endl;
}else{
cout << ASUM.at(endidx) << endl;
}
}
}