Submission #104653

# Submission time Handle Problem Language Result Execution time Memory
104653 2019-04-08T14:07:37 Z IOrtroiii Two Dishes (JOI19_dishes) C++14
100 / 100
8938 ms 253064 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1000100;
const long long inf = 1e18;

int a[N], b[N];
long long s[N], t[N];
int p[N], q[N];
long long sa[N], sb[N];
map< pair<int, int>, long long> change;

long long T[N << 2], lz[N << 2];

void push(int v,int l,int r) {
  if (lz[v]) {
    T[v] += lz[v];
    if (l < r) {
      lz[v << 1] += lz[v];
      lz[v << 1 | 1] += lz[v];
    }
    lz[v] = 0;
  }
}

void upd(int v,int l,int r,int x,long long y) {
  push(v, l, r);
  if (x < l || x > r) return;
  if (l == r) {
    T[v] = max(T[v], y);
    return;
  }
  int md = (l + r) >> 1;
  upd(v << 1, l, md, x, y);
  upd(v << 1 | 1, md + 1, r, x, y);
  T[v] = max(T[v << 1], T[v << 1 | 1]);
}

void add(int v,int l,int r,int L,int R,long long x) {
  push(v, l, r);
  if (L > r || R < l || L > R) return;
  if (L <= l && r <= R) {
    lz[v] = x;
    push(v, l, r);
    return;
  }
  int md = (l + r) >> 1;
  add(v << 1, l, md, L, R, x);
  add(v << 1 | 1, md + 1, r, L, R, x);
  T[v] = max(T[v << 1], T[v << 1 | 1]);
}

long long get(int v,int l,int r,int L,int R) {
  push(v, l, r);
  if (L > r || R < l || L > r) return -inf;
  if (L <= l && r <= R) return T[v];
  int md = (l + r) >> 1;
  return max(get(v << 1, l, md, L, R), get(v << 1 | 1, md + 1, r, L, R));
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %lld %d", a + i, s + i, p + i);
    sa[i] = sa[i - 1] + a[i];
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d %lld %d", b + i, t + i, q + i);
    sb[i] = sb[i - 1] + b[i];
  }
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (sa[i] > s[i]) continue;
    else if (sa[i] + sb[m] <= s[i]) sum += p[i];
    else {
      int nw = upper_bound(sb + 1, sb + 1 + m, s[i] - sa[i]) - sb - 1;
      change[{i - 1, -nw - 1}] += p[i];
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (sb[i] > t[i]) continue;
    else if (sb[i] + sa[n] <= t[i]) sum += q[i];
    else {
      int nw = upper_bound(sa + 1, sa + 1 + n, t[i] - sb[i]) - sa - 1;
      sum += q[i];
      change[{nw, -i}] -= q[i];
    }
  }
  for (auto p : change) {
    int x = p.first.first;
    int y = -p.first.second;
    long long val = p.second;
    long long nw = get(1, 0, m + 5, 0, y - 1);
    upd(1, 0, m + 5, y, nw);
    add(1, 0, m + 5, 0, y - 1, val);
  }
  printf("%lld\n", T[1] + sum);
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:92:9: warning: unused variable 'x' [-Wunused-variable]
     int x = p.first.first;
         ^
dishes.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
dishes.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld %d", a + i, s + i, p + i);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld %d", b + i, t + i, q + i);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 521 ms 45788 KB Output is correct
2 Correct 494 ms 45304 KB Output is correct
3 Correct 218 ms 23288 KB Output is correct
4 Correct 388 ms 36488 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 426 ms 40968 KB Output is correct
7 Correct 136 ms 12152 KB Output is correct
8 Correct 110 ms 12024 KB Output is correct
9 Correct 240 ms 24184 KB Output is correct
10 Correct 457 ms 38012 KB Output is correct
11 Correct 157 ms 17528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
19 Correct 8 ms 896 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 7 ms 868 KB Output is correct
22 Correct 8 ms 768 KB Output is correct
23 Correct 7 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
19 Correct 8 ms 896 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 7 ms 868 KB Output is correct
22 Correct 8 ms 768 KB Output is correct
23 Correct 7 ms 896 KB Output is correct
24 Correct 356 ms 32888 KB Output is correct
25 Correct 390 ms 40992 KB Output is correct
26 Correct 466 ms 41244 KB Output is correct
27 Correct 391 ms 41336 KB Output is correct
28 Correct 463 ms 35144 KB Output is correct
29 Correct 207 ms 21112 KB Output is correct
30 Correct 1219 ms 52872 KB Output is correct
31 Correct 291 ms 24824 KB Output is correct
32 Correct 151 ms 16544 KB Output is correct
33 Correct 701 ms 40572 KB Output is correct
34 Correct 944 ms 47992 KB Output is correct
35 Correct 1214 ms 46956 KB Output is correct
36 Correct 1057 ms 46072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
19 Correct 8 ms 896 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 7 ms 868 KB Output is correct
22 Correct 8 ms 768 KB Output is correct
23 Correct 7 ms 896 KB Output is correct
24 Correct 356 ms 32888 KB Output is correct
25 Correct 390 ms 40992 KB Output is correct
26 Correct 466 ms 41244 KB Output is correct
27 Correct 391 ms 41336 KB Output is correct
28 Correct 463 ms 35144 KB Output is correct
29 Correct 207 ms 21112 KB Output is correct
30 Correct 1219 ms 52872 KB Output is correct
31 Correct 291 ms 24824 KB Output is correct
32 Correct 151 ms 16544 KB Output is correct
33 Correct 701 ms 40572 KB Output is correct
34 Correct 944 ms 47992 KB Output is correct
35 Correct 1214 ms 46956 KB Output is correct
36 Correct 1057 ms 46072 KB Output is correct
37 Correct 434 ms 44192 KB Output is correct
38 Correct 431 ms 44152 KB Output is correct
39 Correct 492 ms 41592 KB Output is correct
40 Correct 470 ms 41592 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1292 ms 55928 KB Output is correct
43 Correct 751 ms 43364 KB Output is correct
44 Correct 1075 ms 50648 KB Output is correct
45 Correct 1140 ms 49912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
19 Correct 8 ms 896 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 7 ms 868 KB Output is correct
22 Correct 8 ms 768 KB Output is correct
23 Correct 7 ms 896 KB Output is correct
24 Correct 356 ms 32888 KB Output is correct
25 Correct 390 ms 40992 KB Output is correct
26 Correct 466 ms 41244 KB Output is correct
27 Correct 391 ms 41336 KB Output is correct
28 Correct 463 ms 35144 KB Output is correct
29 Correct 207 ms 21112 KB Output is correct
30 Correct 1219 ms 52872 KB Output is correct
31 Correct 291 ms 24824 KB Output is correct
32 Correct 151 ms 16544 KB Output is correct
33 Correct 701 ms 40572 KB Output is correct
34 Correct 944 ms 47992 KB Output is correct
35 Correct 1214 ms 46956 KB Output is correct
36 Correct 1057 ms 46072 KB Output is correct
37 Correct 434 ms 44192 KB Output is correct
38 Correct 431 ms 44152 KB Output is correct
39 Correct 492 ms 41592 KB Output is correct
40 Correct 470 ms 41592 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1292 ms 55928 KB Output is correct
43 Correct 751 ms 43364 KB Output is correct
44 Correct 1075 ms 50648 KB Output is correct
45 Correct 1140 ms 49912 KB Output is correct
46 Correct 2323 ms 149376 KB Output is correct
47 Correct 2269 ms 149168 KB Output is correct
48 Correct 2466 ms 147808 KB Output is correct
49 Correct 2628 ms 147508 KB Output is correct
50 Correct 8938 ms 209248 KB Output is correct
51 Correct 4581 ms 142468 KB Output is correct
52 Correct 6221 ms 168988 KB Output is correct
53 Correct 7851 ms 201312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 521 ms 45788 KB Output is correct
2 Correct 494 ms 45304 KB Output is correct
3 Correct 218 ms 23288 KB Output is correct
4 Correct 388 ms 36488 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 426 ms 40968 KB Output is correct
7 Correct 136 ms 12152 KB Output is correct
8 Correct 110 ms 12024 KB Output is correct
9 Correct 240 ms 24184 KB Output is correct
10 Correct 457 ms 38012 KB Output is correct
11 Correct 157 ms 17528 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 356 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 8 ms 768 KB Output is correct
30 Correct 8 ms 896 KB Output is correct
31 Correct 6 ms 768 KB Output is correct
32 Correct 7 ms 868 KB Output is correct
33 Correct 8 ms 768 KB Output is correct
34 Correct 7 ms 896 KB Output is correct
35 Correct 356 ms 32888 KB Output is correct
36 Correct 390 ms 40992 KB Output is correct
37 Correct 466 ms 41244 KB Output is correct
38 Correct 391 ms 41336 KB Output is correct
39 Correct 463 ms 35144 KB Output is correct
40 Correct 207 ms 21112 KB Output is correct
41 Correct 1219 ms 52872 KB Output is correct
42 Correct 291 ms 24824 KB Output is correct
43 Correct 151 ms 16544 KB Output is correct
44 Correct 701 ms 40572 KB Output is correct
45 Correct 944 ms 47992 KB Output is correct
46 Correct 1214 ms 46956 KB Output is correct
47 Correct 1057 ms 46072 KB Output is correct
48 Correct 434 ms 44192 KB Output is correct
49 Correct 431 ms 44152 KB Output is correct
50 Correct 492 ms 41592 KB Output is correct
51 Correct 470 ms 41592 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1292 ms 55928 KB Output is correct
54 Correct 751 ms 43364 KB Output is correct
55 Correct 1075 ms 50648 KB Output is correct
56 Correct 1140 ms 49912 KB Output is correct
57 Correct 456 ms 44744 KB Output is correct
58 Correct 456 ms 44792 KB Output is correct
59 Correct 461 ms 42564 KB Output is correct
60 Correct 456 ms 42456 KB Output is correct
61 Correct 1367 ms 53820 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 1243 ms 56056 KB Output is correct
64 Correct 682 ms 43384 KB Output is correct
65 Correct 924 ms 50684 KB Output is correct
66 Correct 1185 ms 49144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 521 ms 45788 KB Output is correct
2 Correct 494 ms 45304 KB Output is correct
3 Correct 218 ms 23288 KB Output is correct
4 Correct 388 ms 36488 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 426 ms 40968 KB Output is correct
7 Correct 136 ms 12152 KB Output is correct
8 Correct 110 ms 12024 KB Output is correct
9 Correct 240 ms 24184 KB Output is correct
10 Correct 457 ms 38012 KB Output is correct
11 Correct 157 ms 17528 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 356 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 8 ms 768 KB Output is correct
30 Correct 8 ms 896 KB Output is correct
31 Correct 6 ms 768 KB Output is correct
32 Correct 7 ms 868 KB Output is correct
33 Correct 8 ms 768 KB Output is correct
34 Correct 7 ms 896 KB Output is correct
35 Correct 356 ms 32888 KB Output is correct
36 Correct 390 ms 40992 KB Output is correct
37 Correct 466 ms 41244 KB Output is correct
38 Correct 391 ms 41336 KB Output is correct
39 Correct 463 ms 35144 KB Output is correct
40 Correct 207 ms 21112 KB Output is correct
41 Correct 1219 ms 52872 KB Output is correct
42 Correct 291 ms 24824 KB Output is correct
43 Correct 151 ms 16544 KB Output is correct
44 Correct 701 ms 40572 KB Output is correct
45 Correct 944 ms 47992 KB Output is correct
46 Correct 1214 ms 46956 KB Output is correct
47 Correct 1057 ms 46072 KB Output is correct
48 Correct 434 ms 44192 KB Output is correct
49 Correct 431 ms 44152 KB Output is correct
50 Correct 492 ms 41592 KB Output is correct
51 Correct 470 ms 41592 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1292 ms 55928 KB Output is correct
54 Correct 751 ms 43364 KB Output is correct
55 Correct 1075 ms 50648 KB Output is correct
56 Correct 1140 ms 49912 KB Output is correct
57 Correct 2323 ms 149376 KB Output is correct
58 Correct 2269 ms 149168 KB Output is correct
59 Correct 2466 ms 147808 KB Output is correct
60 Correct 2628 ms 147508 KB Output is correct
61 Correct 8938 ms 209248 KB Output is correct
62 Correct 4581 ms 142468 KB Output is correct
63 Correct 6221 ms 168988 KB Output is correct
64 Correct 7851 ms 201312 KB Output is correct
65 Correct 456 ms 44744 KB Output is correct
66 Correct 456 ms 44792 KB Output is correct
67 Correct 461 ms 42564 KB Output is correct
68 Correct 456 ms 42456 KB Output is correct
69 Correct 1367 ms 53820 KB Output is correct
70 Correct 2 ms 384 KB Output is correct
71 Correct 1243 ms 56056 KB Output is correct
72 Correct 682 ms 43384 KB Output is correct
73 Correct 924 ms 50684 KB Output is correct
74 Correct 1185 ms 49144 KB Output is correct
75 Correct 2474 ms 150668 KB Output is correct
76 Correct 2461 ms 150568 KB Output is correct
77 Correct 2633 ms 149016 KB Output is correct
78 Correct 2680 ms 149032 KB Output is correct
79 Correct 8626 ms 210508 KB Output is correct
80 Correct 4321 ms 143844 KB Output is correct
81 Correct 5031 ms 232360 KB Output is correct
82 Correct 8260 ms 205812 KB Output is correct
83 Correct 8013 ms 253064 KB Output is correct