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;
#define all(a) a.begin(), a.end()
#define Base 311
#define endl '\n'
#define fi first
#define fii(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define fill(a,n) memset(a, n, sizeof(a));
#define getbit(i, j) ((i >> j) & 1)
#define minimize(x, y) x = (x > y ? y : x)
#define maximize(x, y) x = (x < y ? y : x)
#define ins insert
// #define int long long
#define ll long long
#define maxn 1000006
#define MOD 1000000007
#define name "file"
#define pb push_back
#define pii pair< int, int >
#define pll pair< long long , long long >
#define re return
#define sz(x) int(x.size())
#define se second
#define ull unsigned long long
void ctime () {
cerr << "\n" << "\nTime elapsed: " << 1000 * clock () / CLOCKS_PER_SEC << "ms\n" ;
}
void iof () {
if ( fopen ( name ".inp" , "r" ))
{
freopen ( name ".inp" , "r" , stdin );
freopen ( name ".out" , "w", stdout );
}
ios_base :: sync_with_stdio ( 0 );
cin . tie ( NULL ), cout . tie ( NULL );
}
ll x[maxn], g[maxn], e[maxn];
ll mx[maxn];
int main(){
iof();
int n;
cin >> n;
fii(i, 1, n)
{
cin >> x[i] >> g[i] >> e[i];
e[i] += e[i - 1];
g[i] += g[i - 1];
mx[i] = -1e13;
}
mx[n + 1] = -1e13;
fid(i, n, 1) mx[i] = max(mx[i + 1], e[i] - x[i]);
ll ans = 0;
fii(i, 1, n)
{
int l = 1, r = n;
int res = 0;
while(l <= r)
{
int mid = (l + r) / 2;
if (mx[mid] >= e[i - 1] - x[i])
{
res = mid;
l = mid + 1;
}
else r = mid - 1;
}
ans = max(ans, g[res] - g[i - 1]);
}
cout << ans;
ctime();
re 0;
}
Compilation message (stderr)
divide.cpp: In function 'void iof()':
divide.cpp:35:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen ( name ".inp" , "r" , stdin );
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:36:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen ( name ".out" , "w", stdout );
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |