#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100000;
unordered_map<ll,int> dp[maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll sum=0;
int n;
cin>>n;
vector<ll>a(n);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++){
sum+=a[i];
dp[i][sum]=1;
}
for(int i=1;i<n;i++){
sum=0;
for(int j=i;j>=1;j--){
sum+=a[j];
for(auto t:dp[j-1]){
if(t.first<=sum){
dp[i][sum]=max(dp[i][sum],t.second+1);
}
}
}
}
int ans=0;
for(auto t:dp[n-1]){
ans=max(ans,t.second);
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5752 KB |
Output is correct |
2 |
Correct |
7 ms |
5880 KB |
Output is correct |
3 |
Correct |
8 ms |
5880 KB |
Output is correct |
4 |
Correct |
8 ms |
5880 KB |
Output is correct |
5 |
Correct |
8 ms |
5752 KB |
Output is correct |
6 |
Correct |
7 ms |
5880 KB |
Output is correct |
7 |
Correct |
7 ms |
5880 KB |
Output is correct |
8 |
Correct |
7 ms |
5752 KB |
Output is correct |
9 |
Correct |
8 ms |
5880 KB |
Output is correct |
10 |
Correct |
9 ms |
5752 KB |
Output is correct |
11 |
Correct |
7 ms |
5880 KB |
Output is correct |
12 |
Correct |
7 ms |
5880 KB |
Output is correct |
13 |
Correct |
7 ms |
5956 KB |
Output is correct |
14 |
Correct |
7 ms |
5864 KB |
Output is correct |
15 |
Correct |
7 ms |
5752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5752 KB |
Output is correct |
2 |
Correct |
7 ms |
5880 KB |
Output is correct |
3 |
Correct |
8 ms |
5880 KB |
Output is correct |
4 |
Correct |
8 ms |
5880 KB |
Output is correct |
5 |
Correct |
8 ms |
5752 KB |
Output is correct |
6 |
Correct |
7 ms |
5880 KB |
Output is correct |
7 |
Correct |
7 ms |
5880 KB |
Output is correct |
8 |
Correct |
7 ms |
5752 KB |
Output is correct |
9 |
Correct |
8 ms |
5880 KB |
Output is correct |
10 |
Correct |
9 ms |
5752 KB |
Output is correct |
11 |
Correct |
7 ms |
5880 KB |
Output is correct |
12 |
Correct |
7 ms |
5880 KB |
Output is correct |
13 |
Correct |
7 ms |
5956 KB |
Output is correct |
14 |
Correct |
7 ms |
5864 KB |
Output is correct |
15 |
Correct |
7 ms |
5752 KB |
Output is correct |
16 |
Correct |
8 ms |
5880 KB |
Output is correct |
17 |
Correct |
281 ms |
10204 KB |
Output is correct |
18 |
Correct |
447 ms |
11208 KB |
Output is correct |
19 |
Correct |
303 ms |
10216 KB |
Output is correct |
20 |
Correct |
416 ms |
11360 KB |
Output is correct |
21 |
Correct |
422 ms |
10908 KB |
Output is correct |
22 |
Correct |
222 ms |
9080 KB |
Output is correct |
23 |
Correct |
95 ms |
7588 KB |
Output is correct |
24 |
Correct |
423 ms |
10928 KB |
Output is correct |
25 |
Correct |
439 ms |
11128 KB |
Output is correct |
26 |
Correct |
535 ms |
11264 KB |
Output is correct |
27 |
Correct |
193 ms |
9088 KB |
Output is correct |
28 |
Correct |
461 ms |
11276 KB |
Output is correct |
29 |
Correct |
598 ms |
11384 KB |
Output is correct |
30 |
Correct |
467 ms |
11256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5752 KB |
Output is correct |
2 |
Correct |
7 ms |
5880 KB |
Output is correct |
3 |
Correct |
8 ms |
5880 KB |
Output is correct |
4 |
Correct |
8 ms |
5880 KB |
Output is correct |
5 |
Correct |
8 ms |
5752 KB |
Output is correct |
6 |
Correct |
7 ms |
5880 KB |
Output is correct |
7 |
Correct |
7 ms |
5880 KB |
Output is correct |
8 |
Correct |
7 ms |
5752 KB |
Output is correct |
9 |
Correct |
8 ms |
5880 KB |
Output is correct |
10 |
Correct |
9 ms |
5752 KB |
Output is correct |
11 |
Correct |
7 ms |
5880 KB |
Output is correct |
12 |
Correct |
7 ms |
5880 KB |
Output is correct |
13 |
Correct |
7 ms |
5956 KB |
Output is correct |
14 |
Correct |
7 ms |
5864 KB |
Output is correct |
15 |
Correct |
7 ms |
5752 KB |
Output is correct |
16 |
Correct |
8 ms |
5880 KB |
Output is correct |
17 |
Correct |
281 ms |
10204 KB |
Output is correct |
18 |
Correct |
447 ms |
11208 KB |
Output is correct |
19 |
Correct |
303 ms |
10216 KB |
Output is correct |
20 |
Correct |
416 ms |
11360 KB |
Output is correct |
21 |
Correct |
422 ms |
10908 KB |
Output is correct |
22 |
Correct |
222 ms |
9080 KB |
Output is correct |
23 |
Correct |
95 ms |
7588 KB |
Output is correct |
24 |
Correct |
423 ms |
10928 KB |
Output is correct |
25 |
Correct |
439 ms |
11128 KB |
Output is correct |
26 |
Correct |
535 ms |
11264 KB |
Output is correct |
27 |
Correct |
193 ms |
9088 KB |
Output is correct |
28 |
Correct |
461 ms |
11276 KB |
Output is correct |
29 |
Correct |
598 ms |
11384 KB |
Output is correct |
30 |
Correct |
467 ms |
11256 KB |
Output is correct |
31 |
Correct |
24 ms |
6108 KB |
Output is correct |
32 |
Execution timed out |
1571 ms |
21624 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5752 KB |
Output is correct |
2 |
Correct |
7 ms |
5880 KB |
Output is correct |
3 |
Correct |
8 ms |
5880 KB |
Output is correct |
4 |
Correct |
8 ms |
5880 KB |
Output is correct |
5 |
Correct |
8 ms |
5752 KB |
Output is correct |
6 |
Correct |
7 ms |
5880 KB |
Output is correct |
7 |
Correct |
7 ms |
5880 KB |
Output is correct |
8 |
Correct |
7 ms |
5752 KB |
Output is correct |
9 |
Correct |
8 ms |
5880 KB |
Output is correct |
10 |
Correct |
9 ms |
5752 KB |
Output is correct |
11 |
Correct |
7 ms |
5880 KB |
Output is correct |
12 |
Correct |
7 ms |
5880 KB |
Output is correct |
13 |
Correct |
7 ms |
5956 KB |
Output is correct |
14 |
Correct |
7 ms |
5864 KB |
Output is correct |
15 |
Correct |
7 ms |
5752 KB |
Output is correct |
16 |
Correct |
8 ms |
5880 KB |
Output is correct |
17 |
Correct |
281 ms |
10204 KB |
Output is correct |
18 |
Correct |
447 ms |
11208 KB |
Output is correct |
19 |
Correct |
303 ms |
10216 KB |
Output is correct |
20 |
Correct |
416 ms |
11360 KB |
Output is correct |
21 |
Correct |
422 ms |
10908 KB |
Output is correct |
22 |
Correct |
222 ms |
9080 KB |
Output is correct |
23 |
Correct |
95 ms |
7588 KB |
Output is correct |
24 |
Correct |
423 ms |
10928 KB |
Output is correct |
25 |
Correct |
439 ms |
11128 KB |
Output is correct |
26 |
Correct |
535 ms |
11264 KB |
Output is correct |
27 |
Correct |
193 ms |
9088 KB |
Output is correct |
28 |
Correct |
461 ms |
11276 KB |
Output is correct |
29 |
Correct |
598 ms |
11384 KB |
Output is correct |
30 |
Correct |
467 ms |
11256 KB |
Output is correct |
31 |
Correct |
24 ms |
6108 KB |
Output is correct |
32 |
Execution timed out |
1571 ms |
21624 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5752 KB |
Output is correct |
2 |
Correct |
7 ms |
5880 KB |
Output is correct |
3 |
Correct |
8 ms |
5880 KB |
Output is correct |
4 |
Correct |
8 ms |
5880 KB |
Output is correct |
5 |
Correct |
8 ms |
5752 KB |
Output is correct |
6 |
Correct |
7 ms |
5880 KB |
Output is correct |
7 |
Correct |
7 ms |
5880 KB |
Output is correct |
8 |
Correct |
7 ms |
5752 KB |
Output is correct |
9 |
Correct |
8 ms |
5880 KB |
Output is correct |
10 |
Correct |
9 ms |
5752 KB |
Output is correct |
11 |
Correct |
7 ms |
5880 KB |
Output is correct |
12 |
Correct |
7 ms |
5880 KB |
Output is correct |
13 |
Correct |
7 ms |
5956 KB |
Output is correct |
14 |
Correct |
7 ms |
5864 KB |
Output is correct |
15 |
Correct |
7 ms |
5752 KB |
Output is correct |
16 |
Correct |
8 ms |
5880 KB |
Output is correct |
17 |
Correct |
281 ms |
10204 KB |
Output is correct |
18 |
Correct |
447 ms |
11208 KB |
Output is correct |
19 |
Correct |
303 ms |
10216 KB |
Output is correct |
20 |
Correct |
416 ms |
11360 KB |
Output is correct |
21 |
Correct |
422 ms |
10908 KB |
Output is correct |
22 |
Correct |
222 ms |
9080 KB |
Output is correct |
23 |
Correct |
95 ms |
7588 KB |
Output is correct |
24 |
Correct |
423 ms |
10928 KB |
Output is correct |
25 |
Correct |
439 ms |
11128 KB |
Output is correct |
26 |
Correct |
535 ms |
11264 KB |
Output is correct |
27 |
Correct |
193 ms |
9088 KB |
Output is correct |
28 |
Correct |
461 ms |
11276 KB |
Output is correct |
29 |
Correct |
598 ms |
11384 KB |
Output is correct |
30 |
Correct |
467 ms |
11256 KB |
Output is correct |
31 |
Correct |
24 ms |
6108 KB |
Output is correct |
32 |
Execution timed out |
1571 ms |
21624 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |