Submission #308197

# Submission time Handle Problem Language Result Execution time Memory
308197 2020-09-30T09:05:09 Z shrek12357 Divide and conquer (IZhO14_divide) C++14
0 / 100
1 ms 384 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
using namespace std;
#define ll long long

const int MAXN = 1e5+5;
#define INF 100000000

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	priority_queue<pair<int, int>, vector<pair<int, int>>, less<pair<int, int>>> pq;
	multiset<int> nums;
	ll best = 0;
	ll pos[MAXN];
	ll gold[MAXN];
	gold[0] = 0;
	ll energy[MAXN];
	energy[0] = 0;
	for (int i = 0; i < n; i++) {
		ll x, g, d;
		cin >> x >> g >> d;
		pos[i] = x;
		gold[i + 1] = gold[i] + g;
		energy[i + 1] = energy[i] + d;
		best = max(best, g);
	}
	/*
	for (int i = 1; i <= n; i++) {
		for (int j = n; j >= i + 1; j--) {
			if (pos[j - 1] - pos[i - 1] <= energy[j] - energy[i - 1]) {
				best = max(best, gold[j] - gold[i - 1]);
				break;
			}
		}
	}
	*/
	for (int i = 1; i <= n; i++) {
		nums.insert(energy[i] - pos[i - 1]);
	}
	for (int i = 1; i <= n; i++) {
		nums.erase(energy[i] - pos[i - 1]);
		pq.push({ energy[i - 1] - pos[i - 1], i });
		while (pq.size() > 0) {
			if (nums.lower_bound(pq.top().first) != nums.end()) {
				break;
			}
			best = max(best, gold[i] - gold[pq.top().second - 1]);
			pq.pop();
		}
	}
	if(pq.size() == 0){
      cout << -3 << endl;
    }
	cout << best << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -