Submission #671833

# Submission time Handle Problem Language Result Execution time Memory
671833 2022-12-14T04:03:48 Z moday_morning Divide and conquer (IZhO14_divide) C++17
100 / 100
35 ms 5980 KB
#include <bits/stdc++.h>
#define int long long
#define fr first
#define sc second
#define pb push_back
using namespace std;
const int INF = 1'000'000'000'000'000'000LL;

void usaco(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

void solve() {
    int n;
    cin >> n;
    int x[n+1], g[n+1], d[n+1];
    d[0] = 0;
    g[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> g[i] >> d[i];
        d[i] += d[i-1];
        g[i] += g[i-1];
    }
 
    vector <pair <int, int>> a, b;
    a.pb({-INF, -INF});
    b.pb({-INF, -INF});
    for(int i = 1; i <= n; i++) {
        a.pb({d[i] - x[i], g[i]});
        b.pb({d[i-1] - x[i], - g[i-1]});
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int sb = -INF, res = 0, ans = 0, cnt = 0;
    for (ans = 1; ans <= n; ans++) {
        while (cnt+1 <= n && b[cnt+1].fr <= a[ans].fr) {
            cnt++;
            sb = max(sb, b[cnt].sc);
        }
        res = max(res, a[ans].sc + sb);
    }
    cout << res << "\n";
}

signed main() {
//    usaco("triangles");
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message

divide.cpp: In function 'void usaco(std::string)':
divide.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 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 340 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 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 792 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 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 340 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 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 792 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 720 KB Output is correct
26 Correct 5 ms 1168 KB Output is correct
27 Correct 4 ms 1232 KB Output is correct
28 Correct 18 ms 4280 KB Output is correct
29 Correct 20 ms 3272 KB Output is correct
30 Correct 35 ms 5968 KB Output is correct
31 Correct 29 ms 5952 KB Output is correct
32 Correct 30 ms 5980 KB Output is correct
33 Correct 30 ms 5972 KB Output is correct
34 Correct 31 ms 5976 KB Output is correct
35 Correct 30 ms 5976 KB Output is correct
36 Correct 33 ms 5952 KB Output is correct