제출 #91000

#제출 시각아이디문제언어결과실행 시간메모리
91000Nodir_Bobiev금 캐기 (IZhO14_divide)C++14
100 / 100
40 ms8808 KiB
# include <bits/stdc++.h>

# define ll long long
# define fi first
# define se second

using namespace std;

const ll  INF = 8e18 + 10;
const ll  MOD = 1e9 + 7;
const int N = 1e5 + 10;
const int Z = 5e4 + 10;

ll n;
ll x[N], g[N], e[N], pf[N], ans;

void solve()
{
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> x[i] >> g[i] >> e[i];
		g[i] += g[i - 1];
		e[i] += e[i - 1];
		pf[i] = min(pf[i - 1], e[i - 1] - x[i]);
		//cout << pf[i] << ' ';
	}
	
	for (int i = 1; i <= n; i++){
		int l = 1, m, r = i;
		ans = max(ans, g[i] - g[i - 1]);
		
		while(r >= l){
			m = (l + r) >> 1;
			
			if(pf[m] <= e[i] - x[i]){
				ans = max(ans, g[i] - g[m - 1]);
				r = m - 1;
			}
			else 
				l = m + 1;
		}
	}
	cout << ans;
}


int main()
{
	int TE = 1;
	ios_base::sync_with_stdio(false);
	//freopen("sort.in", "r", stdin);
	//freopen("sort.out", "w", stdout);
	//cin >> TE;
	
	while(TE --)
		solve();
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...