Submission #396375

# Submission time Handle Problem Language Result Execution time Memory
396375 2021-04-29T21:16:11 Z jeroenodb Divide and conquer (IZhO14_divide) C++14
100 / 100
123 ms 4000 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 bad(const el& nw) const {
        return pref <= nw.pref;
    }
};
int main() {
    int n; cin >> n;
    ll sum = 0,pref=0, ans = 0;
    vector<el> st; st.reserve(n);
    for(int i=0;i<n;++i) {
        int x,g,d; cin >> x >> g >> d;


        el nw = {pref-x,sum};
        if(st.empty() or !st.back().bad(nw))
            st.push_back(nw);
        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);
        }
        pref += d;
        sum+=g;
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 3 ms 312 KB Output is correct
23 Correct 6 ms 460 KB Output is correct
24 Correct 6 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 3 ms 312 KB Output is correct
23 Correct 6 ms 460 KB Output is correct
24 Correct 6 ms 460 KB Output is correct
25 Correct 4 ms 332 KB Output is correct
26 Correct 8 ms 432 KB Output is correct
27 Correct 10 ms 460 KB Output is correct
28 Correct 48 ms 1304 KB Output is correct
29 Correct 58 ms 1604 KB Output is correct
30 Correct 123 ms 3140 KB Output is correct
31 Correct 88 ms 1948 KB Output is correct
32 Correct 93 ms 2080 KB Output is correct
33 Correct 85 ms 1860 KB Output is correct
34 Correct 91 ms 2624 KB Output is correct
35 Correct 104 ms 3912 KB Output is correct
36 Correct 109 ms 4000 KB Output is correct