Submission #108848

# Submission time Handle Problem Language Result Execution time Memory
108848 2019-05-02T09:51:51 Z antimirage Two Dishes (JOI19_dishes) C++14
100 / 100
8039 ms 273564 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 497 ms 32452 KB Output is correct
2 Correct 504 ms 31432 KB Output is correct
3 Correct 250 ms 23224 KB Output is correct
4 Correct 334 ms 36472 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 416 ms 41080 KB Output is correct
7 Correct 104 ms 12024 KB Output is correct
8 Correct 94 ms 12152 KB Output is correct
9 Correct 189 ms 24304 KB Output is correct
10 Correct 413 ms 37968 KB Output is correct
11 Correct 122 ms 17656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 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 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 4 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 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 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 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 4 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 2 ms 384 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 6 ms 844 KB Output is correct
19 Correct 8 ms 896 KB Output is correct
20 Correct 11 ms 768 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 8 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 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 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 4 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 2 ms 384 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 6 ms 844 KB Output is correct
19 Correct 8 ms 896 KB Output is correct
20 Correct 11 ms 768 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 8 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 382 ms 32900 KB Output is correct
25 Correct 504 ms 41204 KB Output is correct
26 Correct 423 ms 41372 KB Output is correct
27 Correct 387 ms 41244 KB Output is correct
28 Correct 436 ms 35188 KB Output is correct
29 Correct 175 ms 21240 KB Output is correct
30 Correct 1146 ms 52928 KB Output is correct
31 Correct 182 ms 24824 KB Output is correct
32 Correct 130 ms 16632 KB Output is correct
33 Correct 653 ms 40576 KB Output is correct
34 Correct 947 ms 48024 KB Output is correct
35 Correct 987 ms 46840 KB Output is correct
36 Correct 963 ms 46116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 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 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 4 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 2 ms 384 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 6 ms 844 KB Output is correct
19 Correct 8 ms 896 KB Output is correct
20 Correct 11 ms 768 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 8 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 382 ms 32900 KB Output is correct
25 Correct 504 ms 41204 KB Output is correct
26 Correct 423 ms 41372 KB Output is correct
27 Correct 387 ms 41244 KB Output is correct
28 Correct 436 ms 35188 KB Output is correct
29 Correct 175 ms 21240 KB Output is correct
30 Correct 1146 ms 52928 KB Output is correct
31 Correct 182 ms 24824 KB Output is correct
32 Correct 130 ms 16632 KB Output is correct
33 Correct 653 ms 40576 KB Output is correct
34 Correct 947 ms 48024 KB Output is correct
35 Correct 987 ms 46840 KB Output is correct
36 Correct 963 ms 46116 KB Output is correct
37 Correct 437 ms 44252 KB Output is correct
38 Correct 468 ms 44244 KB Output is correct
39 Correct 501 ms 41692 KB Output is correct
40 Correct 454 ms 41672 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1335 ms 56184 KB Output is correct
43 Correct 604 ms 43396 KB Output is correct
44 Correct 911 ms 50680 KB Output is correct
45 Correct 1067 ms 50128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 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 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 4 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 2 ms 384 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 6 ms 844 KB Output is correct
19 Correct 8 ms 896 KB Output is correct
20 Correct 11 ms 768 KB Output is correct
21 Correct 7 ms 768 KB Output is correct
22 Correct 8 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 382 ms 32900 KB Output is correct
25 Correct 504 ms 41204 KB Output is correct
26 Correct 423 ms 41372 KB Output is correct
27 Correct 387 ms 41244 KB Output is correct
28 Correct 436 ms 35188 KB Output is correct
29 Correct 175 ms 21240 KB Output is correct
30 Correct 1146 ms 52928 KB Output is correct
31 Correct 182 ms 24824 KB Output is correct
32 Correct 130 ms 16632 KB Output is correct
33 Correct 653 ms 40576 KB Output is correct
34 Correct 947 ms 48024 KB Output is correct
35 Correct 987 ms 46840 KB Output is correct
36 Correct 963 ms 46116 KB Output is correct
37 Correct 437 ms 44252 KB Output is correct
38 Correct 468 ms 44244 KB Output is correct
39 Correct 501 ms 41692 KB Output is correct
40 Correct 454 ms 41672 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1335 ms 56184 KB Output is correct
43 Correct 604 ms 43396 KB Output is correct
44 Correct 911 ms 50680 KB Output is correct
45 Correct 1067 ms 50128 KB Output is correct
46 Correct 2430 ms 212908 KB Output is correct
47 Correct 2375 ms 212788 KB Output is correct
48 Correct 2398 ms 199168 KB Output is correct
49 Correct 2325 ms 199104 KB Output is correct
50 Correct 7869 ms 272952 KB Output is correct
51 Correct 4236 ms 204060 KB Output is correct
52 Correct 5588 ms 229644 KB Output is correct
53 Correct 7740 ms 237220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 32452 KB Output is correct
2 Correct 504 ms 31432 KB Output is correct
3 Correct 250 ms 23224 KB Output is correct
4 Correct 334 ms 36472 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 416 ms 41080 KB Output is correct
7 Correct 104 ms 12024 KB Output is correct
8 Correct 94 ms 12152 KB Output is correct
9 Correct 189 ms 24304 KB Output is correct
10 Correct 413 ms 37968 KB Output is correct
11 Correct 122 ms 17656 KB Output is correct
12 Correct 2 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 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 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 4 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 2 ms 384 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 6 ms 844 KB Output is correct
30 Correct 8 ms 896 KB Output is correct
31 Correct 11 ms 768 KB Output is correct
32 Correct 7 ms 768 KB Output is correct
33 Correct 8 ms 768 KB Output is correct
34 Correct 6 ms 768 KB Output is correct
35 Correct 382 ms 32900 KB Output is correct
36 Correct 504 ms 41204 KB Output is correct
37 Correct 423 ms 41372 KB Output is correct
38 Correct 387 ms 41244 KB Output is correct
39 Correct 436 ms 35188 KB Output is correct
40 Correct 175 ms 21240 KB Output is correct
41 Correct 1146 ms 52928 KB Output is correct
42 Correct 182 ms 24824 KB Output is correct
43 Correct 130 ms 16632 KB Output is correct
44 Correct 653 ms 40576 KB Output is correct
45 Correct 947 ms 48024 KB Output is correct
46 Correct 987 ms 46840 KB Output is correct
47 Correct 963 ms 46116 KB Output is correct
48 Correct 437 ms 44252 KB Output is correct
49 Correct 468 ms 44244 KB Output is correct
50 Correct 501 ms 41692 KB Output is correct
51 Correct 454 ms 41672 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1335 ms 56184 KB Output is correct
54 Correct 604 ms 43396 KB Output is correct
55 Correct 911 ms 50680 KB Output is correct
56 Correct 1067 ms 50128 KB Output is correct
57 Correct 424 ms 44820 KB Output is correct
58 Correct 413 ms 44792 KB Output is correct
59 Correct 441 ms 42616 KB Output is correct
60 Correct 451 ms 42456 KB Output is correct
61 Correct 1258 ms 53864 KB Output is correct
62 Correct 2 ms 428 KB Output is correct
63 Correct 1436 ms 56104 KB Output is correct
64 Correct 704 ms 43344 KB Output is correct
65 Correct 957 ms 50720 KB Output is correct
66 Correct 1168 ms 49236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 32452 KB Output is correct
2 Correct 504 ms 31432 KB Output is correct
3 Correct 250 ms 23224 KB Output is correct
4 Correct 334 ms 36472 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 416 ms 41080 KB Output is correct
7 Correct 104 ms 12024 KB Output is correct
8 Correct 94 ms 12152 KB Output is correct
9 Correct 189 ms 24304 KB Output is correct
10 Correct 413 ms 37968 KB Output is correct
11 Correct 122 ms 17656 KB Output is correct
12 Correct 2 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 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 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 4 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 2 ms 384 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 6 ms 844 KB Output is correct
30 Correct 8 ms 896 KB Output is correct
31 Correct 11 ms 768 KB Output is correct
32 Correct 7 ms 768 KB Output is correct
33 Correct 8 ms 768 KB Output is correct
34 Correct 6 ms 768 KB Output is correct
35 Correct 382 ms 32900 KB Output is correct
36 Correct 504 ms 41204 KB Output is correct
37 Correct 423 ms 41372 KB Output is correct
38 Correct 387 ms 41244 KB Output is correct
39 Correct 436 ms 35188 KB Output is correct
40 Correct 175 ms 21240 KB Output is correct
41 Correct 1146 ms 52928 KB Output is correct
42 Correct 182 ms 24824 KB Output is correct
43 Correct 130 ms 16632 KB Output is correct
44 Correct 653 ms 40576 KB Output is correct
45 Correct 947 ms 48024 KB Output is correct
46 Correct 987 ms 46840 KB Output is correct
47 Correct 963 ms 46116 KB Output is correct
48 Correct 437 ms 44252 KB Output is correct
49 Correct 468 ms 44244 KB Output is correct
50 Correct 501 ms 41692 KB Output is correct
51 Correct 454 ms 41672 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1335 ms 56184 KB Output is correct
54 Correct 604 ms 43396 KB Output is correct
55 Correct 911 ms 50680 KB Output is correct
56 Correct 1067 ms 50128 KB Output is correct
57 Correct 2430 ms 212908 KB Output is correct
58 Correct 2375 ms 212788 KB Output is correct
59 Correct 2398 ms 199168 KB Output is correct
60 Correct 2325 ms 199104 KB Output is correct
61 Correct 7869 ms 272952 KB Output is correct
62 Correct 4236 ms 204060 KB Output is correct
63 Correct 5588 ms 229644 KB Output is correct
64 Correct 7740 ms 237220 KB Output is correct
65 Correct 424 ms 44820 KB Output is correct
66 Correct 413 ms 44792 KB Output is correct
67 Correct 441 ms 42616 KB Output is correct
68 Correct 451 ms 42456 KB Output is correct
69 Correct 1258 ms 53864 KB Output is correct
70 Correct 2 ms 428 KB Output is correct
71 Correct 1436 ms 56104 KB Output is correct
72 Correct 704 ms 43344 KB Output is correct
73 Correct 957 ms 50720 KB Output is correct
74 Correct 1168 ms 49236 KB Output is correct
75 Correct 2314 ms 214624 KB Output is correct
76 Correct 2298 ms 214576 KB Output is correct
77 Correct 2587 ms 201604 KB Output is correct
78 Correct 2244 ms 201612 KB Output is correct
79 Correct 6750 ms 273564 KB Output is correct
80 Correct 4197 ms 204372 KB Output is correct
81 Correct 6103 ms 232312 KB Output is correct
82 Correct 8039 ms 240268 KB Output is correct
83 Correct 7428 ms 252948 KB Output is correct