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>
# define pb push_back
# define fr first
# define sc second
# define mk make_pair
using namespace std;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
typedef long long ll;
int n, a[N];
ll ans, b[N], c[N];
void dv(int l, int r, int opl, int opr)
{
if(l > r) return ;
int md = (l + r) >> 1;;
ll opt, res = 0;
for(int i = opl; i <= min(md, opr); i ++)
{
res = b[md] - b[i - 1];
ll sum = c[md] - c[i - 1];
opt = i;
if(sum >= a[md] - a[i])
break;
}
ans = max(ans, res);
dv(l, md - 1, opl, opt);
dv(md + 1, r, opt, opr);
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i] >> b[i] >> c[i];
b[i] += b[i - 1];
c[i] += c[i - 1];
}
dv(1, n, 1, n);
// for(int i = 1; i <= n; i ++)
// {
// for(int j = 1; j <= i; j ++)
// {
// ll res = b[i] - b[j - 1], sum = c[i] - c[j - 1];
// if(sum < a[i] - a[j]) continue;
// ans = max(ans, res);
// break;
// }
// }
cout << ans << endl;
}
Compilation message (stderr)
divide.cpp: In function 'void dv(int, int, int, int)':
divide.cpp:33:9: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
dv(l, md - 1, opl, opt);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |