Submission #679515

# Submission time Handle Problem Language Result Execution time Memory
679515 2023-01-08T12:40:32 Z keta_tsimakuridze Two Dishes (JOI19_dishes) C++14
82 / 100
10000 ms 192936 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18; // !
int lazy[4 * N][2], a[N][2], c[N][2], s[N][2], n[2];
vector<pii> x[N];
int t[4 * N];
int merge(int x, int y) {
    return max(x, y);
}
void push(int u, int l, int r) {
    if(lazy[u][0] != -inf) {
        t[u] = lazy[u][0];
        if(l < r) {
            lazy[2 * u][1] = lazy[2 * u + 1][1] = 0;
            lazy[2 * u][0] = lazy[2 * u + 1][0] = lazy[u][0];
        }
        lazy[u][0] = -inf;
    }
    if(lazy[u][1] != 0) {
        t[u] += lazy[u][1];
        if(l < r) {
            lazy[2 * u][1] += lazy[u][1];
            lazy[2 * u + 1][1] += lazy[u][1];
        }
        lazy[u][1] = 0;
    }
}
void upd(int u, int st, int en, int l, int r, int x, int T) {
    push(u, l, r);
    if(l > en || r < st) return;
    if(st <= l && r <= en) {
        lazy[u][T] = x;
        push(u, l, r);
        return;
    }
    int mid = (l + r) / 2;
    upd(2 * u, st, en, l, mid, x, T); upd(2 * u + 1, st, en, mid + 1, r, x, T);
    t[u] = merge(t[2 * u], t[2 * u + 1]);
}
int get(int u, int st, int en, int l, int r) {
    push(u, l, r);
    if(l > en || r < st) return -inf;
    if(st <= l && r <= en) return t[u];
    int mid = (l + r) / 2;

    int x = merge(get(2 * u, st, en, l, mid), get(2 * u + 1, st, en, mid + 1, r));
    t[u] = merge(t[2 * u], t[2 * u + 1]);
    return x;
}
main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int  m;
    cin >> n[0] >> n[1];
    for(int t = 0; t < 2; t++) {
        for(int i = 1; i <= n[t]; i++) {
            cin >> a[i][t] >> s[i][t] >> c[i][t];
            a[i][t] += a[i - 1][t];
        }
    }
    int ans = 0;
    for(int t = 0; t < 2; t++) {
        int R = n[t^1];
        for(int i = 1; i <= n[t]; i++) {

            int l = 0, r = n[t^1], R = -1;

            while(l <= r) {
                int mid = (l + r) / 2;
                if(a[i][t] + a[mid][t^1] <= s[i][t]) R = mid, l = mid + 1;
                else r = mid - 1;
            }
            if(!t) {
                // R tu aris i - s win mashin ver vigebt
                ++R;
                ans += c[i][t];
                if(R == n[1] + 1) continue;
                x[i].push_back({R, -c[i][t]});
                continue;
            }
            ++R;
            if(R == n[0] + 1) {
                ans += c[i][t];
                continue;
            }
            // R tu aris i - s shemdeg mashin vigebt
            // i tu aris R - is win mashin vigebt

            x[R].push_back({i, c[i][t]});
        }
    }
/*
    vector<int> dp(n[1] + 1);
    for(int i = 1; i <= n[0]; i++) {
        for(int j = 1; j <= n[1]; j++) dp[j] = max(dp[j], dp[j - 1]);
        sort(x[i].begin(), x[i].end());

        for(int k = 0; k < x[i].size(); k++) {
            for(int j = x[i][k].f; j <= n[1]; j++) dp[j] += x[i][k].s;
        }
    }
    int mn = -inf;
    for(int i = 0; i <= n[1]; i++) mn = max(mn, dp[i]);
    cout << ans + mn << "\n";
    return 0; */
//    build(1, 0, n[1]);
    for(int i = 1; i <= n[0]; i++) {
        x[i].push_back({0, 0});
        x[i].push_back({n[1] + 1, 0});
        sort(x[i].begin(), x[i].end());
        int c = 0, mx = -inf;
        vector<int> v;
        for(int j = 0; j + 1 < x[i].size(); j++) {
            c += x[i][j].s;
            if(x[i][j + 1].f != x[i][j].f) {
                upd(1, x[i][j].f, -1 + x[i][j + 1].f, 0, n[1], c, 1);
                int mx = get(1, 0, x[i][j].f - 1, 0, n[1]);
                int l = x[i][j].f, r = -1 + x[i][j + 1].f, id = x[i][j].f - 1;
                while(l <= r) {
                    int mid = (l + r) / 2;
                    if(get(1, mid, mid, 0, n[1]) <= mx) id = mid, l = mid + 1;
                    else r = mid - 1;
                }
                upd(1, x[i][j].f, id, 0, n[1], mx, 0);
            }
        }
    }
    cout << t[1] + ans;

 }

Compilation message

dishes.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main(){
      | ^~~~
dishes.cpp: In function 'int main()':
dishes.cpp:66:13: warning: unused variable 'R' [-Wunused-variable]
   66 |         int R = n[t^1];
      |             ^
dishes.cpp:116:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |         for(int j = 0; j + 1 < x[i].size(); j++) {
      |                        ~~~~~~^~~~~~~~~~~~~
dishes.cpp:114:20: warning: unused variable 'mx' [-Wunused-variable]
  114 |         int c = 0, mx = -inf;
      |                    ^~
dishes.cpp:56:10: warning: unused variable 'm' [-Wunused-variable]
   56 |     int  m;
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 2150 ms 64988 KB Output is correct
2 Correct 2112 ms 63748 KB Output is correct
3 Correct 1049 ms 42992 KB Output is correct
4 Correct 1766 ms 60172 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 1894 ms 61944 KB Output is correct
7 Correct 95 ms 34432 KB Output is correct
8 Correct 107 ms 42588 KB Output is correct
9 Correct 1022 ms 43132 KB Output is correct
10 Correct 2141 ms 61164 KB Output is correct
11 Correct 967 ms 43132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 23764 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23832 KB Output is correct
5 Correct 15 ms 23780 KB Output is correct
6 Correct 14 ms 23840 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 13 ms 23792 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23736 KB Output is correct
11 Correct 12 ms 23788 KB Output is correct
12 Correct 14 ms 23768 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 13 ms 23716 KB Output is correct
16 Correct 13 ms 23836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 23764 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23832 KB Output is correct
5 Correct 15 ms 23780 KB Output is correct
6 Correct 14 ms 23840 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 13 ms 23792 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23736 KB Output is correct
11 Correct 12 ms 23788 KB Output is correct
12 Correct 14 ms 23768 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 13 ms 23716 KB Output is correct
16 Correct 13 ms 23836 KB Output is correct
17 Correct 19 ms 24228 KB Output is correct
18 Correct 18 ms 24208 KB Output is correct
19 Correct 42 ms 24264 KB Output is correct
20 Correct 23 ms 24276 KB Output is correct
21 Correct 25 ms 24196 KB Output is correct
22 Correct 27 ms 24240 KB Output is correct
23 Correct 27 ms 24200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 23764 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23832 KB Output is correct
5 Correct 15 ms 23780 KB Output is correct
6 Correct 14 ms 23840 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 13 ms 23792 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23736 KB Output is correct
11 Correct 12 ms 23788 KB Output is correct
12 Correct 14 ms 23768 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 13 ms 23716 KB Output is correct
16 Correct 13 ms 23836 KB Output is correct
17 Correct 19 ms 24228 KB Output is correct
18 Correct 18 ms 24208 KB Output is correct
19 Correct 42 ms 24264 KB Output is correct
20 Correct 23 ms 24276 KB Output is correct
21 Correct 25 ms 24196 KB Output is correct
22 Correct 27 ms 24240 KB Output is correct
23 Correct 27 ms 24200 KB Output is correct
24 Correct 1334 ms 50836 KB Output is correct
25 Correct 1256 ms 61116 KB Output is correct
26 Correct 2122 ms 62764 KB Output is correct
27 Correct 2223 ms 61196 KB Output is correct
28 Correct 2000 ms 59048 KB Output is correct
29 Correct 1085 ms 43096 KB Output is correct
30 Correct 4539 ms 65836 KB Output is correct
31 Correct 204 ms 47140 KB Output is correct
32 Correct 121 ms 45696 KB Output is correct
33 Correct 2901 ms 64416 KB Output is correct
34 Correct 3334 ms 63764 KB Output is correct
35 Correct 4215 ms 65864 KB Output is correct
36 Correct 4351 ms 65604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 23764 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23832 KB Output is correct
5 Correct 15 ms 23780 KB Output is correct
6 Correct 14 ms 23840 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 13 ms 23792 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23736 KB Output is correct
11 Correct 12 ms 23788 KB Output is correct
12 Correct 14 ms 23768 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 13 ms 23716 KB Output is correct
16 Correct 13 ms 23836 KB Output is correct
17 Correct 19 ms 24228 KB Output is correct
18 Correct 18 ms 24208 KB Output is correct
19 Correct 42 ms 24264 KB Output is correct
20 Correct 23 ms 24276 KB Output is correct
21 Correct 25 ms 24196 KB Output is correct
22 Correct 27 ms 24240 KB Output is correct
23 Correct 27 ms 24200 KB Output is correct
24 Correct 1334 ms 50836 KB Output is correct
25 Correct 1256 ms 61116 KB Output is correct
26 Correct 2122 ms 62764 KB Output is correct
27 Correct 2223 ms 61196 KB Output is correct
28 Correct 2000 ms 59048 KB Output is correct
29 Correct 1085 ms 43096 KB Output is correct
30 Correct 4539 ms 65836 KB Output is correct
31 Correct 204 ms 47140 KB Output is correct
32 Correct 121 ms 45696 KB Output is correct
33 Correct 2901 ms 64416 KB Output is correct
34 Correct 3334 ms 63764 KB Output is correct
35 Correct 4215 ms 65864 KB Output is correct
36 Correct 4351 ms 65604 KB Output is correct
37 Correct 2185 ms 62680 KB Output is correct
38 Correct 2181 ms 61220 KB Output is correct
39 Correct 2183 ms 61180 KB Output is correct
40 Correct 2173 ms 61156 KB Output is correct
41 Correct 14 ms 23764 KB Output is correct
42 Correct 4508 ms 65836 KB Output is correct
43 Correct 2947 ms 64304 KB Output is correct
44 Correct 3752 ms 63672 KB Output is correct
45 Correct 4939 ms 65852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 23764 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23832 KB Output is correct
5 Correct 15 ms 23780 KB Output is correct
6 Correct 14 ms 23840 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 13 ms 23792 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23736 KB Output is correct
11 Correct 12 ms 23788 KB Output is correct
12 Correct 14 ms 23768 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 13 ms 23716 KB Output is correct
16 Correct 13 ms 23836 KB Output is correct
17 Correct 19 ms 24228 KB Output is correct
18 Correct 18 ms 24208 KB Output is correct
19 Correct 42 ms 24264 KB Output is correct
20 Correct 23 ms 24276 KB Output is correct
21 Correct 25 ms 24196 KB Output is correct
22 Correct 27 ms 24240 KB Output is correct
23 Correct 27 ms 24200 KB Output is correct
24 Correct 1334 ms 50836 KB Output is correct
25 Correct 1256 ms 61116 KB Output is correct
26 Correct 2122 ms 62764 KB Output is correct
27 Correct 2223 ms 61196 KB Output is correct
28 Correct 2000 ms 59048 KB Output is correct
29 Correct 1085 ms 43096 KB Output is correct
30 Correct 4539 ms 65836 KB Output is correct
31 Correct 204 ms 47140 KB Output is correct
32 Correct 121 ms 45696 KB Output is correct
33 Correct 2901 ms 64416 KB Output is correct
34 Correct 3334 ms 63764 KB Output is correct
35 Correct 4215 ms 65864 KB Output is correct
36 Correct 4351 ms 65604 KB Output is correct
37 Correct 2185 ms 62680 KB Output is correct
38 Correct 2181 ms 61220 KB Output is correct
39 Correct 2183 ms 61180 KB Output is correct
40 Correct 2173 ms 61156 KB Output is correct
41 Correct 14 ms 23764 KB Output is correct
42 Correct 4508 ms 65836 KB Output is correct
43 Correct 2947 ms 64304 KB Output is correct
44 Correct 3752 ms 63672 KB Output is correct
45 Correct 4939 ms 65852 KB Output is correct
46 Execution timed out 10081 ms 192936 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2150 ms 64988 KB Output is correct
2 Correct 2112 ms 63748 KB Output is correct
3 Correct 1049 ms 42992 KB Output is correct
4 Correct 1766 ms 60172 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 1894 ms 61944 KB Output is correct
7 Correct 95 ms 34432 KB Output is correct
8 Correct 107 ms 42588 KB Output is correct
9 Correct 1022 ms 43132 KB Output is correct
10 Correct 2141 ms 61164 KB Output is correct
11 Correct 967 ms 43132 KB Output is correct
12 Correct 13 ms 23764 KB Output is correct
13 Correct 14 ms 23764 KB Output is correct
14 Correct 13 ms 23764 KB Output is correct
15 Correct 13 ms 23832 KB Output is correct
16 Correct 15 ms 23780 KB Output is correct
17 Correct 14 ms 23840 KB Output is correct
18 Correct 13 ms 23772 KB Output is correct
19 Correct 13 ms 23792 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 13 ms 23736 KB Output is correct
22 Correct 12 ms 23788 KB Output is correct
23 Correct 14 ms 23768 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 13 ms 23804 KB Output is correct
26 Correct 13 ms 23716 KB Output is correct
27 Correct 13 ms 23836 KB Output is correct
28 Correct 19 ms 24228 KB Output is correct
29 Correct 18 ms 24208 KB Output is correct
30 Correct 42 ms 24264 KB Output is correct
31 Correct 23 ms 24276 KB Output is correct
32 Correct 25 ms 24196 KB Output is correct
33 Correct 27 ms 24240 KB Output is correct
34 Correct 27 ms 24200 KB Output is correct
35 Correct 1334 ms 50836 KB Output is correct
36 Correct 1256 ms 61116 KB Output is correct
37 Correct 2122 ms 62764 KB Output is correct
38 Correct 2223 ms 61196 KB Output is correct
39 Correct 2000 ms 59048 KB Output is correct
40 Correct 1085 ms 43096 KB Output is correct
41 Correct 4539 ms 65836 KB Output is correct
42 Correct 204 ms 47140 KB Output is correct
43 Correct 121 ms 45696 KB Output is correct
44 Correct 2901 ms 64416 KB Output is correct
45 Correct 3334 ms 63764 KB Output is correct
46 Correct 4215 ms 65864 KB Output is correct
47 Correct 4351 ms 65604 KB Output is correct
48 Correct 2185 ms 62680 KB Output is correct
49 Correct 2181 ms 61220 KB Output is correct
50 Correct 2183 ms 61180 KB Output is correct
51 Correct 2173 ms 61156 KB Output is correct
52 Correct 14 ms 23764 KB Output is correct
53 Correct 4508 ms 65836 KB Output is correct
54 Correct 2947 ms 64304 KB Output is correct
55 Correct 3752 ms 63672 KB Output is correct
56 Correct 4939 ms 65852 KB Output is correct
57 Correct 2197 ms 62700 KB Output is correct
58 Correct 2185 ms 61304 KB Output is correct
59 Correct 2164 ms 61148 KB Output is correct
60 Correct 2187 ms 61224 KB Output is correct
61 Correct 3917 ms 66000 KB Output is correct
62 Correct 13 ms 23764 KB Output is correct
63 Correct 4145 ms 66108 KB Output is correct
64 Correct 2622 ms 64660 KB Output is correct
65 Correct 3366 ms 63144 KB Output is correct
66 Correct 4062 ms 65800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2150 ms 64988 KB Output is correct
2 Correct 2112 ms 63748 KB Output is correct
3 Correct 1049 ms 42992 KB Output is correct
4 Correct 1766 ms 60172 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 1894 ms 61944 KB Output is correct
7 Correct 95 ms 34432 KB Output is correct
8 Correct 107 ms 42588 KB Output is correct
9 Correct 1022 ms 43132 KB Output is correct
10 Correct 2141 ms 61164 KB Output is correct
11 Correct 967 ms 43132 KB Output is correct
12 Correct 13 ms 23764 KB Output is correct
13 Correct 14 ms 23764 KB Output is correct
14 Correct 13 ms 23764 KB Output is correct
15 Correct 13 ms 23832 KB Output is correct
16 Correct 15 ms 23780 KB Output is correct
17 Correct 14 ms 23840 KB Output is correct
18 Correct 13 ms 23772 KB Output is correct
19 Correct 13 ms 23792 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 13 ms 23736 KB Output is correct
22 Correct 12 ms 23788 KB Output is correct
23 Correct 14 ms 23768 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 13 ms 23804 KB Output is correct
26 Correct 13 ms 23716 KB Output is correct
27 Correct 13 ms 23836 KB Output is correct
28 Correct 19 ms 24228 KB Output is correct
29 Correct 18 ms 24208 KB Output is correct
30 Correct 42 ms 24264 KB Output is correct
31 Correct 23 ms 24276 KB Output is correct
32 Correct 25 ms 24196 KB Output is correct
33 Correct 27 ms 24240 KB Output is correct
34 Correct 27 ms 24200 KB Output is correct
35 Correct 1334 ms 50836 KB Output is correct
36 Correct 1256 ms 61116 KB Output is correct
37 Correct 2122 ms 62764 KB Output is correct
38 Correct 2223 ms 61196 KB Output is correct
39 Correct 2000 ms 59048 KB Output is correct
40 Correct 1085 ms 43096 KB Output is correct
41 Correct 4539 ms 65836 KB Output is correct
42 Correct 204 ms 47140 KB Output is correct
43 Correct 121 ms 45696 KB Output is correct
44 Correct 2901 ms 64416 KB Output is correct
45 Correct 3334 ms 63764 KB Output is correct
46 Correct 4215 ms 65864 KB Output is correct
47 Correct 4351 ms 65604 KB Output is correct
48 Correct 2185 ms 62680 KB Output is correct
49 Correct 2181 ms 61220 KB Output is correct
50 Correct 2183 ms 61180 KB Output is correct
51 Correct 2173 ms 61156 KB Output is correct
52 Correct 14 ms 23764 KB Output is correct
53 Correct 4508 ms 65836 KB Output is correct
54 Correct 2947 ms 64304 KB Output is correct
55 Correct 3752 ms 63672 KB Output is correct
56 Correct 4939 ms 65852 KB Output is correct
57 Execution timed out 10081 ms 192936 KB Time limit exceeded
58 Halted 0 ms 0 KB -