#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
bool check(ll mid, int x, vector<ll> v) {
ll curr = 0;
int cnt = 1, n = v.size();
for(int i = 0; i < n; i++) {
if(v[i] > mid) return false;
if(curr + v[i] > mid) {
curr = v[i];
cnt++;
}
else curr += v[i];
}
return cnt <= x;
}
ll calc(ll mn, vector<ll> v) {
ll ans = 0, curr = 0;
int n = v.size();
for(int i = 0; i < n; i++) {
if(curr+v[i] > mn) {
ans |= curr;
curr = v[i];
}
else curr += v[i];
}
ans |= curr;
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, a, b;
cin >> n >> a >> b;
vector<ll> v(n);
ll s = 0;
for(int i = 0; i < n; i++) {
cin >> v[i];
s += v[i];
}
ll ans = INF;
for(int i = a; i <= n; i++) {
ll l = 0, r = s, mn = INF;
while(l <= r) {
ll mid = (l+r)/2;
if(check(mid, i, v)) {
mn = min(mn, mid);
r = mid-1;
}
else l = mid+1;
}
ans = min(ans, calc(mn, v));
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
456 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |