Submission #384562

# Submission time Handle Problem Language Result Execution time Memory
384562 2021-04-01T20:51:13 Z ritul_kr_singh Divide and conquer (IZhO14_divide) C++17
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'

signed main(){
	cin.tie(0)->sync_with_stdio(0);

	int n, ans = 0; cin >> n;
	vector<int> a(n+1), b(n+1), c(n+1);
	for(int i=1; i<=n; ++i){
		cin >> c[i] >> b[i] >> a[i];
		ans = max(ans, b[i]);
		a[i] += a[i-1];
		b[i] += b[i-1];
	}
	for(int i=0; i<n; ++i) a[i] -= c[i+1];
	for(int i=1; i<=n; ++i) a[i] = min(a[i], a[i-1]);

	for(int i=1; i<=n; ++i){
		int sub = (i < n ?  c[i+1] : 0LL);
		int low = 0, high = i;
		while(low<high){
			int mid = (low+high)/2;
			if(a[mid] <= a[i] + sub - c[i]) high = mid;
			else low = mid+1;
		}
		ans = max(ans, b[i] - b[low]);
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -