結果
問題 | No.1007 コイン集め |
ユーザー |
|
提出日時 | 2020-03-09 01:56:46 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 686 ms / 1,500 ms |
コード長 | 1,559 bytes |
コンパイル時間 | 2,026 ms |
コンパイル使用メモリ | 76,700 KB |
実行使用メモリ | 49,452 KB |
最終ジャッジ日時 | 2024-11-07 20:25:04 |
合計ジャッジ時間 | 10,980 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
import java.util.*; class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); long[] A=new long[N]; long ans=0; for(int i=0;i<N;i++){ A[i]=sc.nextLong(); } if(A[K-1]==0){ System.out.println(0); }else if(A[K-1]==1){ for(int i=0;i<K-1;i++){ if(A[i]<=1){ ans=A[i]; }else{ ans+=A[i]; } } long ANS=ans; ans=0; for(int i=K;i<N;i++){ if(A[i]<=1){ ans+=A[i]; break; }else{ ans+=A[i]; } } ANS++; ans++; if(ANS>ans){ System.out.println(ANS); }else{ System.out.println(ans); } }else{ boolean through=false; for(int i=0;i<N;i++){ if(i==K-1){ through=true; } if(A[i]<=1&&!(through)){ ans=A[i]; }else if(A[i]<=1&&through){ ans+=A[i]; System.out.println(ans); return; }else{ ans+=A[i]; } } System.out.println(ans); } } }