# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
308186 | shrek12357 | 금 캐기 (IZhO14_divide) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
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.push_back(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;
}
}
}
cout << best << endl;
}