Submission #375843

# Submission time Handle Problem Language Result Execution time Memory
375843 2021-03-10T04:23:40 Z 2qbingxuan Two Dishes (JOI19_dishes) C++14
74 / 100
2442 ms 227480 KB
#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\n")));
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local

using namespace std;
const int maxn = 1000025;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;

struct Item {
    int t;
    int64_t ed;
    int val;
} v[maxn], u[maxn];
int64_t sumv[maxn], sumu[maxn];
int posv[maxn], posu[maxn];
int64_t dp[maxn], dif[maxn], lim[maxn];
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> v[i].t >> v[i].ed >> v[i].val;
    for (int i = 1; i <= m; i++)
        cin >> u[i].t >> u[i].ed >> u[i].val;

    for (int i = 1; i <= n; i++)
        sumv[i] = sumv[i-1] + v[i].t;
    for (int i = 1; i <= m; i++)
        sumu[i] = sumu[i-1] + u[i].t;

    for (int i = 1; i <= n; i++)
        posv[i] = upper_bound(sumu, sumu+m+1, v[i].ed - sumv[i]) - sumu - 1;
    for (int i = 1; i <= m; i++)
        posu[i] = upper_bound(sumv, sumv+n+1, u[i].ed - sumu[i]) - sumv - 1;

    for (int j = 1; j <= m; j++) dp[j] = dp[j-1] + (posu[j] >= 0 ? u[j].val : 0);
    for (int j = 1; j <= m; j++) lim[j] = dif[j] = (posu[j] >= 0 ? u[j].val : 0);

    /*
    cerr << "posu:\t";
    cerr << 0 << ' ';
    for (int i = 1; i <= m; i++) cerr << posu[i] << ' ';
    cerr << '\n';
    cerr << "u.val:\t";
    cerr << 0 << ' ';
    for (int i = 1; i <= m; i++) cerr << u[i].val << ' ';
    cerr << '\n';
    */

    set<int> st;
    min_heap<pair<int,int>> pq;
    for (int j = 1; j <= m; j++) if (posu[j] >= 0) pq.emplace(posu[j], j);

    function<void(int,int,int64_t)> update = [&](int i, int j, int64_t val) {
        if (val == 0 || j == m+1) return;
        if (val < 0) {
            dif[j] += val;
            st.insert(j);
            return;
        }
        if (dif[j] - val <= lim[j]) {
            int64_t c = lim[j] - (dif[j] - val);
            dif[j] = lim[j];
            st.erase(j);
            auto it = st.lower_bound(j);
            if (it != st.end())
                update(i, *it, c);
        } else {
            dif[j] -= val;
        }
        // int64_t c = max<int64_t>(0, (j != 0 && i <= posu[j] ? u[j].val : 0) - dif[j]);
    };
    for (int i = 1; i <= n; i++) {
        while (!pq.empty() && i > pq.top().first) {
            int j = pq.top().second;
            pq.pop();
            lim[j] = 0;
            if (dif[j] > lim[j])
                st.insert(j);
        }

        dif[0] += v[i].val;
        update(i, posv[i]+1, v[i].val);


        /*
        for (int j = 0; j <= posv[i]; j++) dp[j] += v[i].val;
        for (int j = 1; j <= m; j++) dp[j] = max(dp[j], dp[j-1] + (i <= posu[j] ? u[j].val : 0));

        cerr << posv[i] << ';' << v[i].val << ";\t";
        for (int j = 0; j <= m; j++) cerr << (dp[j] - (j ? dp[j-1] : 0)) << ' ';
        cerr << '\n';
        */
    }
    debug(dp[m]);
    int64_t sum = 0;
    for (int i = 0; i <= m; i++) sum += dif[i];
    cout << sum << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 260 ms 28900 KB Output is correct
2 Correct 230 ms 21096 KB Output is correct
3 Correct 186 ms 21352 KB Output is correct
4 Correct 233 ms 25704 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 237 ms 20584 KB Output is correct
7 Correct 94 ms 14312 KB Output is correct
8 Correct 89 ms 7404 KB Output is correct
9 Correct 207 ms 21480 KB Output is correct
10 Correct 197 ms 21352 KB Output is correct
11 Correct 134 ms 21352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 166 ms 20460 KB Output is correct
25 Correct 223 ms 30564 KB Output is correct
26 Correct 171 ms 20836 KB Output is correct
27 Correct 240 ms 30820 KB Output is correct
28 Correct 211 ms 21940 KB Output is correct
29 Correct 164 ms 22248 KB Output is correct
30 Correct 342 ms 21992 KB Output is correct
31 Correct 113 ms 18404 KB Output is correct
32 Correct 77 ms 7404 KB Output is correct
33 Correct 261 ms 20588 KB Output is correct
34 Correct 327 ms 25444 KB Output is correct
35 Correct 300 ms 22248 KB Output is correct
36 Correct 298 ms 22504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 166 ms 20460 KB Output is correct
25 Correct 223 ms 30564 KB Output is correct
26 Correct 171 ms 20836 KB Output is correct
27 Correct 240 ms 30820 KB Output is correct
28 Correct 211 ms 21940 KB Output is correct
29 Correct 164 ms 22248 KB Output is correct
30 Correct 342 ms 21992 KB Output is correct
31 Correct 113 ms 18404 KB Output is correct
32 Correct 77 ms 7404 KB Output is correct
33 Correct 261 ms 20588 KB Output is correct
34 Correct 327 ms 25444 KB Output is correct
35 Correct 300 ms 22248 KB Output is correct
36 Correct 298 ms 22504 KB Output is correct
37 Correct 222 ms 22124 KB Output is correct
38 Correct 265 ms 31972 KB Output is correct
39 Correct 282 ms 47204 KB Output is correct
40 Correct 212 ms 22804 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 392 ms 23144 KB Output is correct
43 Correct 289 ms 22016 KB Output is correct
44 Correct 358 ms 25828 KB Output is correct
45 Correct 347 ms 22248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 166 ms 20460 KB Output is correct
25 Correct 223 ms 30564 KB Output is correct
26 Correct 171 ms 20836 KB Output is correct
27 Correct 240 ms 30820 KB Output is correct
28 Correct 211 ms 21940 KB Output is correct
29 Correct 164 ms 22248 KB Output is correct
30 Correct 342 ms 21992 KB Output is correct
31 Correct 113 ms 18404 KB Output is correct
32 Correct 77 ms 7404 KB Output is correct
33 Correct 261 ms 20588 KB Output is correct
34 Correct 327 ms 25444 KB Output is correct
35 Correct 300 ms 22248 KB Output is correct
36 Correct 298 ms 22504 KB Output is correct
37 Correct 222 ms 22124 KB Output is correct
38 Correct 265 ms 31972 KB Output is correct
39 Correct 282 ms 47204 KB Output is correct
40 Correct 212 ms 22804 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 392 ms 23144 KB Output is correct
43 Correct 289 ms 22016 KB Output is correct
44 Correct 358 ms 25828 KB Output is correct
45 Correct 347 ms 22248 KB Output is correct
46 Correct 1018 ms 99692 KB Output is correct
47 Correct 1360 ms 149200 KB Output is correct
48 Correct 1880 ms 227480 KB Output is correct
49 Correct 1059 ms 102720 KB Output is correct
50 Correct 2442 ms 102988 KB Output is correct
51 Correct 1623 ms 96868 KB Output is correct
52 Correct 2108 ms 114212 KB Output is correct
53 Correct 2074 ms 103136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 260 ms 28900 KB Output is correct
2 Correct 230 ms 21096 KB Output is correct
3 Correct 186 ms 21352 KB Output is correct
4 Correct 233 ms 25704 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 237 ms 20584 KB Output is correct
7 Correct 94 ms 14312 KB Output is correct
8 Correct 89 ms 7404 KB Output is correct
9 Correct 207 ms 21480 KB Output is correct
10 Correct 197 ms 21352 KB Output is correct
11 Correct 134 ms 21352 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 2 ms 620 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 3 ms 620 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 3 ms 620 KB Output is correct
35 Correct 166 ms 20460 KB Output is correct
36 Correct 223 ms 30564 KB Output is correct
37 Correct 171 ms 20836 KB Output is correct
38 Correct 240 ms 30820 KB Output is correct
39 Correct 211 ms 21940 KB Output is correct
40 Correct 164 ms 22248 KB Output is correct
41 Correct 342 ms 21992 KB Output is correct
42 Correct 113 ms 18404 KB Output is correct
43 Correct 77 ms 7404 KB Output is correct
44 Correct 261 ms 20588 KB Output is correct
45 Correct 327 ms 25444 KB Output is correct
46 Correct 300 ms 22248 KB Output is correct
47 Correct 298 ms 22504 KB Output is correct
48 Correct 222 ms 22124 KB Output is correct
49 Correct 265 ms 31972 KB Output is correct
50 Correct 282 ms 47204 KB Output is correct
51 Correct 212 ms 22804 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 392 ms 23144 KB Output is correct
54 Correct 289 ms 22016 KB Output is correct
55 Correct 358 ms 25828 KB Output is correct
56 Correct 347 ms 22248 KB Output is correct
57 Incorrect 248 ms 29416 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 260 ms 28900 KB Output is correct
2 Correct 230 ms 21096 KB Output is correct
3 Correct 186 ms 21352 KB Output is correct
4 Correct 233 ms 25704 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 237 ms 20584 KB Output is correct
7 Correct 94 ms 14312 KB Output is correct
8 Correct 89 ms 7404 KB Output is correct
9 Correct 207 ms 21480 KB Output is correct
10 Correct 197 ms 21352 KB Output is correct
11 Correct 134 ms 21352 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 2 ms 620 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 3 ms 620 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 3 ms 620 KB Output is correct
35 Correct 166 ms 20460 KB Output is correct
36 Correct 223 ms 30564 KB Output is correct
37 Correct 171 ms 20836 KB Output is correct
38 Correct 240 ms 30820 KB Output is correct
39 Correct 211 ms 21940 KB Output is correct
40 Correct 164 ms 22248 KB Output is correct
41 Correct 342 ms 21992 KB Output is correct
42 Correct 113 ms 18404 KB Output is correct
43 Correct 77 ms 7404 KB Output is correct
44 Correct 261 ms 20588 KB Output is correct
45 Correct 327 ms 25444 KB Output is correct
46 Correct 300 ms 22248 KB Output is correct
47 Correct 298 ms 22504 KB Output is correct
48 Correct 222 ms 22124 KB Output is correct
49 Correct 265 ms 31972 KB Output is correct
50 Correct 282 ms 47204 KB Output is correct
51 Correct 212 ms 22804 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 392 ms 23144 KB Output is correct
54 Correct 289 ms 22016 KB Output is correct
55 Correct 358 ms 25828 KB Output is correct
56 Correct 347 ms 22248 KB Output is correct
57 Correct 1018 ms 99692 KB Output is correct
58 Correct 1360 ms 149200 KB Output is correct
59 Correct 1880 ms 227480 KB Output is correct
60 Correct 1059 ms 102720 KB Output is correct
61 Correct 2442 ms 102988 KB Output is correct
62 Correct 1623 ms 96868 KB Output is correct
63 Correct 2108 ms 114212 KB Output is correct
64 Correct 2074 ms 103136 KB Output is correct
65 Incorrect 248 ms 29416 KB Output isn't correct
66 Halted 0 ms 0 KB -