This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |