Submission #392574

# Submission time Handle Problem Language Result Execution time Memory
392574 2021-04-21T10:43:56 Z vanic Divide and conquer (IZhO14_divide) C++14
17 / 100
1 ms 336 KB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <array>

using namespace std;

typedef long long ll;
const int maxn=1e5+5;

struct logaritamska{
	ll l[maxn];
	void update(int x, int val){
		for(; x<maxn; x+=(x & -x)){
			l[x]+=val;
		}
	}
	ll query(int x){
		ll sol=0;
		for(; x>0; x-=(x & -x)){
			sol+=l[x];
		}
		return sol;
	}
};

inline int rev(int x){
	return maxn-x-1;
}

logaritamska L;
int l[maxn][3];
ll pref[maxn];

int binary(int x){
	int lo=0, hi=x, mid;
	while(lo<hi){
		mid=(lo+hi)/2;
		if(L.query(rev(mid))>0){
			lo=mid+1;
		}
		else{
			hi=mid;
		}
	}
	return lo;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> l[i][0] >> l[i][1] >> l[i][2];
		pref[i+1]=pref[i]+l[i][1];
	}
	int pos;
	ll val=0;
	for(int i=0; i<n; i++){
		L.update(rev(i), -l[i][2]);
		if(i){
			L.update(rev(i-1), l[i][0]-l[i-1][0]);
		}
		pos=binary(i);
		val=max(val, pref[i+1]-pref[pos]);
//		cout << i  <<  ' ' << pos <<  endl;
	}
	cout << val << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Incorrect 1 ms 336 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Incorrect 1 ms 336 KB Output isn't correct
16 Halted 0 ms 0 KB -