답안 #643886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643886 2022-09-23T07:51:13 Z ghostwriter 금 캐기 (IZhO14_divide) C++14
100 / 100
60 ms 7120 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) (x).bg(), (x).ed()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    VOI23 gold medal
*/
const ll oo = 1e18;
const int N = 1e5 + 5;
const int Nx2 = 2e5 + 5;
int n, x[N], g[N], d[N];
ll f[N], s[N], f1[Nx2], rs = -oo;
vll v;
int getpos(ll x) { return lb(all(v), x) - v.bg(); }
void upd(int pos, ll v) { for (int i = pos; i >= 1; i -= (i & -i)) f1[i] = min(f1[i], v); }
ll get(int pos) { ll rs = oo; for (int i = pos; i < sz(v); i += (i & -i)) rs = min(rs, f1[i]); return rs; }
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    cin >> n;
    FOR(i, 1, n) cin >> x[i] >> g[i] >> d[i];
    FOR(i, 1, n) {
    	f[i] = f[i - 1] + d[i];
    	s[i] = s[i - 1] + g[i];
    	v.pb(-f[i] + x[i]);
    	v.pb(-f[i - 1] + x[i]);
    }
    v.pb(-oo);
    sort(all(v));
    FOR(i, 1, sz(v) - 1) f1[i] = oo;
    FOR(i, 1, n) {
    	int pos = getpos(-f[i - 1] + x[i]);
    	upd(pos, s[i - 1]);
    	pos = getpos(-f[i] + x[i]);
    	rs = max(rs, s[i] - get(pos));
    }
    cout << rs;
    return 0;
}
/*
2
0 4 1
3 5 1
*/
/*
From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH
*/

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
divide.cpp:55:5: note: in expansion of macro 'FOR'
   55 |     FOR(i, 1, n) cin >> x[i] >> g[i] >> d[i];
      |     ^~~
divide.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
divide.cpp:56:5: note: in expansion of macro 'FOR'
   56 |     FOR(i, 1, n) {
      |     ^~~
divide.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
divide.cpp:64:5: note: in expansion of macro 'FOR'
   64 |     FOR(i, 1, sz(v) - 1) f1[i] = oo;
      |     ^~~
divide.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
divide.cpp:65:5: note: in expansion of macro 'FOR'
   65 |     FOR(i, 1, n) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 4 ms 712 KB Output is correct
24 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 4 ms 712 KB Output is correct
24 Correct 3 ms 724 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 5 ms 984 KB Output is correct
27 Correct 4 ms 984 KB Output is correct
28 Correct 21 ms 3396 KB Output is correct
29 Correct 25 ms 3408 KB Output is correct
30 Correct 46 ms 6256 KB Output is correct
31 Correct 45 ms 7076 KB Output is correct
32 Correct 43 ms 7120 KB Output is correct
33 Correct 43 ms 7024 KB Output is correct
34 Correct 54 ms 6976 KB Output is correct
35 Correct 52 ms 7060 KB Output is correct
36 Correct 60 ms 7072 KB Output is correct