Submission #344543

# Submission time Handle Problem Language Result Execution time Memory
344543 2021-01-06T05:31:12 Z bachaquer Divide and conquer (IZhO14_divide) C++14
0 / 100
0 ms 364 KB
#include <bits/stdc++.h>

#define ll long long
#define pb push_back

using namespace std;

ll n, x, g, d;

struct lol {
    ll x;
    ll g;
    ll d;
};

int main() {
    freopen("divide.in", "r", stdin);
    freopen("divide.out", "w", stdout);
    cin >> n;
    vector<lol> v;
    for (int i = 0; i < n; i++) {
        cin >> x >> g >> d;
        v.pb({x, g, d});
    }
    ll mx = -1;
    for (int i = 0; i < n; i++) {
        vector<lol> khm;
        khm = v;
        ll sum = 0;
        for (int j = i; j < n; j++) {
            sum += khm[j].g;
            if (khm[j + 1].d + khm[j].d < (khm[j + 1].x - khm[j].x)) break;
            else {
                ll rozn = (khm[j + 1].x - khm[j].x);
                khm[j].d -= rozn;
                if (khm[j].d < 0) {
                    khm[j + 1].d += khm[j].d;
                    khm[j].d = 0;
                }
            }
        }
        mx = max(mx, sum);
    }
    cout << mx;
    return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   17 |     freopen("divide.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     freopen("divide.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -