Submission #738448

# Submission time Handle Problem Language Result Execution time Memory
738448 2023-05-08T19:05:00 Z bane Divide and conquer (IZhO14_divide) C++17
0 / 100
27 ms 47280 KB
#include<bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define debug(x) cout << (#x) << " is " << (x) << '\n'
#else
#define debug(x) 42
#endif

#define int long long

const int maxN = (int)1e6;
int t= 0,n;
unordered_map<int,int>compress;
class Fenwick{
	public:
	int tree[6 * maxN];
	
	void init(){
		for (int i = 0 ; i < 6 * maxN; i++)tree[i] = (int)1e9;
	}
	
	void update(int pos, int val){
		while(pos <= t){
			tree[pos] = min(tree[pos], val);
			pos += pos & (-pos);
		}
	}
	
	int get(int pos){
		int ans = (int)1e9;
		while(pos){
			ans = min(ans, tree[pos]);
			pos -= pos & (-pos);
		}
		return ans;
	}
};
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	vector<vector<int>>a(n,vector<int>(3));
	for (int i = 0; i < n; i++){
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	sort(a.begin(), a.end());
	int len = 0, energy = 0;
	vector<int>b;
	b.push_back(0);
	for (int i = 0; i < n; i++){
		len += a[i][0];
		if (i)len-=a[i-1][0];
		energy += a[i][2];//Cr - Cl <= Er - El, Cr - Er <= Cl - El
		b.push_back(len - energy);
	}
	sort(b.rbegin(), b.rend());
	for (int i = 0; i < (int)b.size(); i++){
		if (!i || b[i] != b[i - 1])compress[b[i]] = ++t;
	}
	len = 0, energy = 0;
	int ans = 0;
	Fenwick tr;
	tr.init();
	int ps[n + 1];
	memset(ps, 0LL, sizeof(ps));
	for (int i = 0; i < n; i++){
		int prev = len - energy;
		len += a[i][0];
		if (i)len-=a[i-1][0];
		energy += a[i][2];
		ps[i + 1] += a[i][1] + ps[i];
		int ask = tr.get(compress[len - energy]);
		int res = ps[i+1] - (ask != (int)1e9 ? ps[ask - 1] : ps[i]);
		tr.update(compress[prev], i+1);
		ans = max(ans, res);
	}
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47188 KB Output is correct
2 Incorrect 27 ms 47280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47188 KB Output is correct
2 Incorrect 27 ms 47280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47188 KB Output is correct
2 Incorrect 27 ms 47280 KB Output isn't correct
3 Halted 0 ms 0 KB -