제출 #655520

#제출 시각아이디문제언어결과실행 시간메모리
655520stevancv금 캐기 (IZhO14_divide)C++14
100 / 100
34 ms6240 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e6 + 2;
const int inf = 2e9;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    vector<ll> x(n + 1), g(n + 1), e(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> g[i] >> e[i];
        g[i] += g[i - 1];
        e[i] += e[i - 1];
    }
    vector<ll> pref(n + 1);
    for (int i = 1; i <= n; i++) pref[i] = max(pref[i - 1], x[i] - e[i - 1]);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int l = 1; int r = i; int id = -1;
        while (l <= r) {
            int mid = l + r >> 1;
            if (pref[mid] >= x[i] - e[i]) {
                r = mid - 1;
                id = mid;
            }
            else l = mid + 1;
        }
        if (id == -1) continue;
        smax(ans, g[i] - g[id - 1]);
    }
    cout << ans << en;
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

divide.cpp: In function 'int main()':
divide.cpp:28:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |             int mid = l + r >> 1;
      |                       ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...