Submission #95426

# Submission time Handle Problem Language Result Execution time Memory
95426 2019-02-01T06:07:34 Z choikiwon Divide and conquer (IZhO14_divide) C++17
100 / 100
59 ms 10196 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MN = 100010;

int N;
int X[MN], G[MN], E[MN];
ll esum[MN], gsum[MN];
vector<pair<ll, int> > ord1, ord2;
priority_queue<int> pq;

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d %d %d", &X[i], &G[i], &E[i]);
    }
    for(int i = 0; i < N; i++) {
        esum[i] = E[i];
        gsum[i] = G[i];
        if(i) {
            esum[i] += esum[i - 1];
            gsum[i] += gsum[i - 1];
        }
    }
    for(int i = 0; i < N; i++) {
        ord1.push_back({ (i? esum[i - 1] : 0) - X[i], i });
        ord2.push_back({ esum[i] - X[i], i });
    }
    sort(ord1.begin(), ord1.end());
    sort(ord2.begin(), ord2.end());

    int pos = (int)ord2.size() - 1;
    ll ans = 0;
    for(int i = (int)ord1.size() - 1; i >= 0; i--) {
        while(pos >= 0 && ord2[pos].first >= ord1[i].first) {
            pq.push(ord2[pos--].second);
        }
        int x = ord1[i].second;
        if(!pq.empty() && pq.top() >= x) {
            ans = max(ans, gsum[ pq.top() ] - (x? gsum[x - 1] : 0));
        }
    }
    printf("%lld", ans);
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
divide.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &X[i], &G[i], &E[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 476 KB Output is correct
11 Correct 4 ms 888 KB Output is correct
12 Correct 4 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 888 KB Output is correct
2 Correct 6 ms 1272 KB Output is correct
3 Correct 7 ms 1396 KB Output is correct
4 Correct 25 ms 4836 KB Output is correct
5 Correct 29 ms 5092 KB Output is correct
6 Correct 59 ms 10196 KB Output is correct
7 Correct 45 ms 8916 KB Output is correct
8 Correct 45 ms 9040 KB Output is correct
9 Correct 43 ms 8872 KB Output is correct
10 Correct 49 ms 8920 KB Output is correct
11 Correct 54 ms 9304 KB Output is correct
12 Correct 53 ms 9560 KB Output is correct