답안 #396373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396373 2021-04-29T21:05:34 Z jeroenodb 금 캐기 (IZhO14_divide) C++14
0 / 100
1 ms 292 KB
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
struct el {
    ll pref, gold;
    bool operator>(const el& o) const {
        return pref < o.pref;
    }
};
int main() {
    int n; cin >> n;
    ll sum = 0,pref=0;
    ll ans = 0;
    vector<el> st; st.reserve(n);
    for(int i=0;i<n;++i) {
        int x,g,d; cin >> x >> g >> d;
        ans = max((ll)g,ans);
        int l=0,r=st.size();

        while(l<r) {
            int mid = (l+r)/2;
            if(st[mid].pref<=pref+d-x) {
                r = mid;
            } else {
                l = mid+1;
            }
        }
        if(l!=(int)st.size()) {
            ans = max(sum+g-st[l].gold, ans);
        }
        if(i==n-1) break;
        el nw = {pref-x,sum};
        while(!st.empty() and st.back()>nw) {
            st.pop_back();
        }
        st.push_back(nw);
        pref += d;
        sum+=g;
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 292 KB Output isn't correct
3 Halted 0 ms 0 KB -