답안 #339192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339192 2020-12-24T20:04:20 Z FlashGamezzz 금 캐기 (IZhO14_divide) C++17
17 / 100
1 ms 492 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
#include <map>

using namespace std;

int n, k, stree[300000] = {};
vector<pair<int, pair<int, int > > > mines;
vector<int> gld, svs; vector<pair<int, int> > nrg;
map<int, int> cc;

void updh(int i, int s, int e, int l, int u, int d) {
	if (s > e || s > u || e < l) {
		return;
	}
	if (s >= l && e <= u) {
		stree[i] = max(stree[i], d); return;
	}
	updh(i*2+1, s, (s+e)/2, l, u, d); updh(i*2+2, (s+e)/2+1, e, l, u, d);
	stree[i] = max(stree[i*2+1], stree[i*2+2]);
}
void updv(int i, int d) {
	updh(0, 0, n, i, i, d);
}
int maxh(int i, int s, int e, int l, int u) {
	if (s > e || s > u || e < l) {
		return 0;
	}
	if (s >= l && e <= u) {
		return stree[i];
	}
	return max(maxh(2*i+1, s, (s+e)/2, l, u), maxh(2*i+2, (s+e)/2+1, e, l, u));
}
int maxv(int l, int u) {
	return maxh(0, 0, n, l, u);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n;
	for (int i = 0; i < n; i++){
		int a, b, c; cin >> a >> b >> c;
		mines.push_back(make_pair(a, make_pair(b, c)));
	}
	int last = 0; gld.push_back(0); nrg.push_back(make_pair(0, 0));
	for (int i = 0; i < n; i++){
		int x = mines[i].first, cnrg = mines[i].second.second, cgld = mines[i].second.first;
		nrg.push_back(make_pair(cnrg+nrg[i].first+last-x, i+1));
		svs.push_back(nrg[i].first-x+last); last = x; gld.push_back(gld[i]+cgld);
	}
	sort(nrg.begin(), nrg.end());
	for (int i = 0; i <= n; i++){
		cc[nrg[i].first] = i;
	}
	for (int i = 0; i <= n; i++){
		updv(cc[nrg[i].first], nrg[i].second);
	}
	int ans = 0;
	for (int i = 0; i < n; i++){
		ans = max(ans, gld[maxv(cc.lower_bound(svs[i])->second, n)]-gld[i]);
	}
	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Incorrect 1 ms 492 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Incorrect 1 ms 492 KB Output isn't correct
18 Halted 0 ms 0 KB -