Submission #172775

# Submission time Handle Problem Language Result Execution time Memory
172775 2020-01-02T15:18:21 Z tselmegkh Divide and conquer (IZhO14_divide) C++14
100 / 100
292 ms 6772 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

int x[N], g[N], d[N];
bool vis[N];

long long tree[4 * N], lazy[4 * N], pref[N];

void push(int v, int l, int r, int val){
	if(l != r){
		lazy[v * 2] += val;
		lazy[v * 2 + 1] += val;
	}
	tree[v] += val;
	lazy[v] = 0;
}
void update(int v, int l, int r, int ql, int qr, int val){
	if(l > r)return;
	push(v, l, r, lazy[v]);
	if(ql > r || qr < l)return;
	if(ql <= l && qr >= r){
		push(v, l, r, val);
		return;
	}
	int mid = (l + r) / 2;
	update(v * 2, l, mid, ql, qr, val);
	update(v * 2 + 1, mid + 1, r, ql, qr, val);
	tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
}
int get(int v, int l, int r){
	push(v, l, r, lazy[v]);
	if(l == r)return l;
	int mid = (l + r) / 2;
	if(tree[v * 2] + lazy[v * 2] >= 0){
		return get(v * 2, l, mid);
	}
	return get(v * 2 + 1, mid + 1, r);
}
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> g[i] >> d[i];
		pref[i] = pref[i - 1] + g[i];
	}

	long long ans = 0;
	for(int i = 1; i <= n; i++){
		if(i > 1)update(1, 1, n, 1, i - 1, x[i - 1] - x[i]);
		update(1, 1, n, 1, i, d[i]);
		int l = get(1, 1, n);
		ans = max(ans, pref[i] - pref[l - 1]);
	}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 476 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 14 ms 888 KB Output is correct
12 Correct 14 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 760 KB Output is correct
2 Correct 19 ms 1144 KB Output is correct
3 Correct 23 ms 1276 KB Output is correct
4 Correct 118 ms 3704 KB Output is correct
5 Correct 135 ms 3584 KB Output is correct
6 Correct 292 ms 6664 KB Output is correct
7 Correct 222 ms 6680 KB Output is correct
8 Correct 227 ms 6652 KB Output is correct
9 Correct 220 ms 6656 KB Output is correct
10 Correct 215 ms 6592 KB Output is correct
11 Correct 254 ms 6772 KB Output is correct
12 Correct 273 ms 6656 KB Output is correct