ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#190605 | #3382. 切纸带 | ddh123 | 100 | 35ms | 16776kb | C++ | 532b | 2023-10-06 14:36:19 | 2023-10-06 18:34:30 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k,a[1000005],dp[1000005],ans;
int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
signed main(){
n=read(),k=read();
for(int i=1,j=0;i<=n;i++){
a[i]=read(),a[i]+=a[i-1];
while(j+1<i&&a[i]-a[j]>k)j++;
if(a[i]-a[j]==k)dp[i]=dp[j]+1;
ans=max(ans,dp[i]);
}
printf("%lld",ans);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1156kb
input:
10 8 7 6 1 1 1 2 2 1 1 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 10
Accepted
time: 1ms
memory: 1160kb
input:
20 15 15 15 15 6 5 4 3 1 2 1 4 3 1 2 1 1 3 2 5 1
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 10
Accepted
time: 0ms
memory: 1160kb
input:
50 150 30 83 136 11 2 94 137 127 111 27 150 150 150 150 150 47 150 145 67 150 150 59 143 142 150 18 ...
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 10
Accepted
time: 0ms
memory: 1156kb
input:
100 10000 2397 9666 164 4643 8586 5876 4272 2648 1874 1206 6920 1732 107 35 778 428 6920 262 888 582...
output:
8
result:
ok 1 number(s): "8"
Test #5:
score: 10
Accepted
time: 0ms
memory: 1168kb
input:
500 278529 33329 243449 856 45 557 153 52 68 9 11 15965 25498 110413 69087 26846 16166 3236 4561 127...
output:
12
result:
ok 1 number(s): "12"
Test #6:
score: 10
Accepted
time: 0ms
memory: 1232kb
input:
5000 1024 369 299 338 137 12 186 10 180 97 117 148 16 8 169 31 44 17 111 24 7 42 12 45 276 67 6 1 2 ...
output:
26
result:
ok 1 number(s): "26"
Test #7:
score: 10
Accepted
time: 0ms
memory: 1932kb
input:
50000 2 1 1 1 2 2 1 1 1 2 1 2 2 2 1 1 1 1 1 1 2 1 1 1 1 1 2 2 2 1 1 1 1 2 2 1 2 2 1 1 1 1 2 1 1 1 1 ...
output:
1435
result:
ok 1 number(s): "1435"
Test #8:
score: 10
Accepted
time: 4ms
memory: 2716kb
input:
100000 2 2 2 1 1 2 2 1 1 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1 2 1 1 2 2 1 2 2 2 2 1 1 2 1 1 2 2 2...
output:
1065
result:
ok 1 number(s): "1065"
Test #9:
score: 10
Accepted
time: 9ms
memory: 2720kb
input:
100000 594914243 32593384 70791539 466102281 5146792 10441404 6860910 391592 109128 1123315 1345154 ...
output:
121
result:
ok 1 number(s): "121"
Test #10:
score: 10
Accepted
time: 21ms
memory: 16776kb
input:
1000000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
850
result:
ok 1 number(s): "850"