Submission #132614

# Submission time Handle Problem Language Result Execution time Memory
132614 2019-07-19T08:36:35 Z alexpetrescu Cloud Computing (CEOI18_clo) C++14
100 / 100
303 ms 1400 KB
#include <cstdio>
#include <algorithm>
#include <vector>

//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");
#define fin stdin
#define fout stdout

struct myc {
    int c, f, v, t;
    inline bool operator < (const myc &u) const {
        if (f != u.f) return f < u.f;
        else return t > u.t;
    }
};

long long d[100009];

inline void _(long long &a, long long b) {
    a = std::max(a, b);
}

int main() {
    int calc;
    fscanf(fin, "%d", &calc);

    std::vector < myc > v;
    for (; calc; calc--) {
        int c, f, V;
        fscanf(fin, "%d%d%d", &c, &f, &V);

        v.push_back({c, f, V, 0});
    }

    int coma;
    fscanf(fin, "%d", &coma);

    for (; coma; coma--) {
        int c, f, V;
        fscanf(fin, "%d%d%d", &c, &f, &V);

        v.push_back({c, f, V, 1});
    }

    std::sort(v.begin(), v.end());

    int sumC = 0;
    for (auto &x : v) {
        if (x.t) {
            for (int i = sumC; i >= 0; i--)
                _(d[i + x.c], d[i] + x.v);
            sumC += x.c;
        } else {
            for (int i = 1; i < x.c; i++)
                _(d[0], d[i] - x.v);
            for (int i = x.c; i <= sumC; i++)
                _(d[i - x.c], d[i] - x.v);
        }
    }

    fprintf(fout, "%lld\n", d[0]);

    return 0;
}

Compilation message

clo.cpp: In function 'int main()':
clo.cpp:25:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin, "%d", &calc);
     ~~~~~~^~~~~~~~~~~~~~~~~~
clo.cpp:30:15: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf(fin, "%d%d%d", &c, &f, &V);
         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:36:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin, "%d", &coma);
     ~~~~~~^~~~~~~~~~~~~~~~~~
clo.cpp:40:15: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf(fin, "%d%d%d", &c, &f, &V);
         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 48 ms 760 KB Output is correct
6 Correct 32 ms 504 KB Output is correct
7 Correct 96 ms 1144 KB Output is correct
8 Correct 91 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 4 ms 360 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 11 ms 504 KB Output is correct
5 Correct 130 ms 968 KB Output is correct
6 Correct 264 ms 1144 KB Output is correct
7 Correct 264 ms 1148 KB Output is correct
8 Correct 256 ms 1272 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 3 ms 376 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 177 ms 1260 KB Output is correct
6 Correct 279 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 48 ms 760 KB Output is correct
6 Correct 32 ms 504 KB Output is correct
7 Correct 96 ms 1144 KB Output is correct
8 Correct 91 ms 1148 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 4 ms 360 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 252 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 11 ms 504 KB Output is correct
30 Correct 130 ms 968 KB Output is correct
31 Correct 264 ms 1144 KB Output is correct
32 Correct 264 ms 1148 KB Output is correct
33 Correct 256 ms 1272 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 7 ms 376 KB Output is correct
38 Correct 177 ms 1260 KB Output is correct
39 Correct 279 ms 1132 KB Output is correct
40 Correct 18 ms 504 KB Output is correct
41 Correct 59 ms 760 KB Output is correct
42 Correct 9 ms 508 KB Output is correct
43 Correct 303 ms 1272 KB Output is correct
44 Correct 296 ms 1400 KB Output is correct
45 Correct 196 ms 1272 KB Output is correct
46 Correct 4 ms 376 KB Output is correct
47 Correct 5 ms 504 KB Output is correct
48 Correct 5 ms 504 KB Output is correct