답안 #36388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36388 2017-12-08T14:56:18 Z cheater2k 금 캐기 (IZhO14_divide) C++14
17 / 100
3 ms 8584 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 200005;

int n;
long long x[N], g[N], d[N];
long long T[N];
long long ans;
vector<long long> z; // for compression

void upd(int x, long long val) { for(; x < N; x += x & -x) T[x] = max(T[x], val); }
long long get(int x) { long long res = 0; for (; x > 0; x -= x & -x) res = max(res, T[x]); return res; }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> x[i] >> g[i] >> d[i], d[i] += d[i-1]; // (coordinate, gold, energy)
	for (int i = 1; i <= n; ++i) {
		// compress all values
		z.push_back(d[i] - x[i]);
		z.push_back(d[i-1] - x[i]);
	}
	sort(z.begin(), z.end());
	z.resize(distance(z.begin(), unique(z.begin(), z.end())));

	for (int i = 1; i <= n; ++i) {
		long long dp = g[i];
		int pos = lower_bound(z.begin(), z.end(), d[i] - x[i]) - z.begin() + 1;
		dp += get(pos);
		pos = lower_bound(z.begin(), z.end(), d[i-1] - x[i]) - z.begin() + 1;
		upd(pos, dp);
		ans = max(ans, dp);
	}

	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8424 KB Output is correct
2 Correct 0 ms 8424 KB Output is correct
3 Correct 0 ms 8424 KB Output is correct
4 Correct 0 ms 8424 KB Output is correct
5 Correct 0 ms 8424 KB Output is correct
6 Correct 0 ms 8424 KB Output is correct
7 Correct 0 ms 8424 KB Output is correct
8 Correct 0 ms 8424 KB Output is correct
9 Correct 0 ms 8424 KB Output is correct
10 Correct 0 ms 8424 KB Output is correct
11 Correct 0 ms 8424 KB Output is correct
12 Correct 0 ms 8424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 8424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 8584 KB Output isn't correct
2 Halted 0 ms 0 KB -