-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
46 lines (44 loc) · 945 Bytes
/
test.cpp
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
37
38
39
40
41
42
43
44
45
46
#include "bits/stdc++.h"
using namespace std;
int maxLength(vector < int > a, int k) {
//sort (a.begin(), a.end());
if (a.size() == 0) return 0;
int cont = 0;
int sum = 0;
int ma = -1;
//a.insert(a.end(),a.begin(),a.end());
int idx = 0;
vector <int> ans;
for (int i = 0; i < a.size(); ++i) {
sum+=a[i];
if (sum <= k) {
++cont;
} else {
//ans.push_back(cont);
ma = max(ma, cont);
cont = 1;
i = ++idx;
sum = a[idx];
}
}
ma = max(ma, cont);
//ans.push_back(cont);
//sort(ans.begin(), ans.end());
//cont = ans[ans.size() - 1];
return ma;
}
int main() {
int TC;
cin >> TC;
//cout << "TC: " << TC << endl;
vector <int > v;
for (int i = 0; i < TC; ++i) {
int temp;
cin >> temp;
v.push_back(temp);
}
int k;
cin >> k;
cout << maxLength(v,k) << endl;
return 0;
}