Submission #00119
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include<bits/stdc++.h> #define ll long long #define endl "\n" using namespace std; int main(){ ll n,k,cheak=0; cin>>n>>k; ll a[n]; for (auto &i:a){ cin>>i; if (i>=k){ cout<< "1\n" ; return (0); } cheak+=i; } if (cheak<k){ cout<< "-1\n" ; return (0); } ll l=0,now=0,ans=10000000000000; for (ll r=0;r<n;r++){ now+=a[r]; while (now-a[l]>=k && l<r){ //cout<<now-a[l]<<' '<<k<<' '; now-=a[l]; l++; } //cout<<l<<' '<<r<<endl; if (now>=k){ //cout<<"a "<<l<<" "<<r<<" "; ans=min(ans,(r-l)+1); } } cout<<ans<<endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0012 - しゃくとり! |
ユーザー名 | ei2406 |
投稿日時 | 2024-07-18 15:48:08 |
言語 | C++17 |
状態 | Wrong Answer |
得点 | 0 |
ソースコード長 | 751 Byte |
最大実行時間 | 57 ms |
最大メモリ使用量 | 1352 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 0 / 33 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in1.txt | AC | 30 ms | 604 KB |
1
|
in2.txt | AC | 49 ms | 1300 KB |
1
|
in3.txt | AC | 57 ms | 1264 KB |
1
|
in4.txt | AC | 36 ms | 1224 KB |
1
|
in5.txt | AC | 36 ms | 1312 KB |
1
|
in6.txt | AC | 20 ms | 512 KB |
1
|
in7.txt | AC | 21 ms | 484 KB |
1
|
in8.txt | WA | 48 ms | 1352 KB |
1
|
in9.txt | AC | 21 ms | 544 KB |
1
|
in10.txt | AC | 16 ms | 576 KB |
1
|
in11.txt | AC | 40 ms | 1196 KB |
1
|
in12.txt | AC | 26 ms | 772 KB |
1
|
in13.txt | AC | 42 ms | 1200 KB |
1
|
in14.txt | AC | 40 ms | 1304 KB |
1
|
in15.txt | AC | 39 ms | 1152 KB |
1
|