# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
198802 | 2020-01-27T18:23:20 Z | Vladikus004 | 금 캐기 (IZhO14_divide) | C++14 | 9 ms | 3320 KB |
#include <bits/stdc++.h> #define inf 2e9 #define ff first #define ss second #define all(v) v.begin() , v.end() using namespace std; typedef long long ll; typedef pair <ll, int> pii; const int N = 100000 + 5; struct obj{ int x, d, g; obj(){ x = g = d = 0; } }; int n; ll pref[N], fenw[2 * N], pref_g[N]; obj a[N]; void up(int ind, ll x){ for (int i = ind; i <= 2 * N; i |= i + 1) fenw[i] = min(fenw[i], x); } ll get_min(int ind){ ll ans = inf; for (int i = ind; i >= 0; i = (i & (i + 1)) - 1) ans = min(ans, fenw[i]); return ans; } void init(){ for (int i = 0; i <= 2 * N; i++) fenw[i] = inf; } map <ll, int> code; int main() { #ifdef VBH freopen("input.txt" , "r" , stdin); #endif freopen("divide.in" , "r" , stdin); freopen("divide.out" , "w" , stdout); ios_base::sync_with_stdio(false); cin.tie(0); init(); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].g >> a[i].d; for (int i = 1; i <= n; i++){ pref_g[i] = a[i].g; pref_g[i] += pref_g[i - 1]; pref[i] = a[i].d; pref[i] += pref[i - 1]; } vector <ll> roman; for (int i = 1; i <= n; i++){ roman.push_back(-a[i].x + pref[i]); roman.push_back(-a[i].x + pref[i - 1]); } sort(roman.begin(), roman.end()); for (int i = 0; i < roman.size(); i++) code[roman[i]] = i; ll ans = 0; for (int i = 1; i <= n; i++){ ans = max(ans, (ll)a[i].g); int ind = code[-a[i].x + pref[i]]; ll mn = get_min(ind); if (mn != inf) ans = max(ans, pref_g[i] - pref_g[mn - 1]); ind = code[-a[i].x + pref[i - 1]]; up(ind, i); } cout << ans; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 3320 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 3064 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 3064 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |