Submission #931453

# Submission time Handle Problem Language Result Execution time Memory
931453 2024-02-21T20:32:01 Z vjudge1 Gym Badges (NOI22_gymbadges) C++17
100 / 100
1600 ms 49028 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 5e5+5, S = 50, inf = LLONG_MAX;

int n, x[N], l[N];
pair<int, int> s[N];
map<int, int> dp[N];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  bool eq = 1;
  for (int i = 0; i < n; i++) {
    cin >> l[i];
    if (l[i] != l[0]) eq = 0;
  }
  for (int i = 0; i < n; i++) {
    s[i] = make_pair(x[i]+l[i], i);
  }
  sort(s, s+n);

  if (eq) {
    int ans = 0;
    int lvl = 0;
    for (int i = 0; i < n; i++) {
      int idx = s[i].second;
      if (lvl <= l[idx]) {
        ans++;
        lvl += x[idx];
      }
    }
    cout << ans << "\n";
  } 
  else {
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;

      auto it = dp[i].end();
      while (it != dp[i].begin()) {
        if (cnt++ > S) break;

        --it;
        int j = it->first;
        int k = it->second;

        auto it2 = dp[i+1].find(j);
        if (it2 == dp[i+1].end()) dp[i+1][j] = k;
        else it2->second = min(it2->second, k);

        if (l[s[i].second] >= k) {
          it2 = dp[i+1].find(j+1);
          if (it2 == dp[i+1].end()) dp[i+1][j+1] = k + x[s[i].second];
          else it2->second = min(it2->second, k + x[s[i].second]);
        } 
      }
      dp[i].clear();
    }

    for (int i = n; i >= 0; i--) {
      if (dp[n].find(i) != dp[n].end()) {
        cout << i << "\n";
        break;
      }
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29272 KB Output is correct
2 Correct 6 ms 29272 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 5 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 5 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 6 ms 29276 KB Output is correct
10 Correct 5 ms 29276 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 5 ms 29276 KB Output is correct
13 Correct 6 ms 29312 KB Output is correct
14 Correct 6 ms 29272 KB Output is correct
15 Correct 5 ms 29272 KB Output is correct
16 Correct 5 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 5 ms 29276 KB Output is correct
19 Correct 5 ms 29276 KB Output is correct
20 Correct 5 ms 29284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 39564 KB Output is correct
2 Correct 113 ms 39564 KB Output is correct
3 Correct 117 ms 39340 KB Output is correct
4 Correct 115 ms 39764 KB Output is correct
5 Correct 112 ms 39504 KB Output is correct
6 Correct 109 ms 39504 KB Output is correct
7 Correct 111 ms 39508 KB Output is correct
8 Correct 115 ms 39512 KB Output is correct
9 Correct 115 ms 39564 KB Output is correct
10 Correct 110 ms 39508 KB Output is correct
11 Correct 119 ms 39508 KB Output is correct
12 Correct 116 ms 39440 KB Output is correct
13 Correct 117 ms 39808 KB Output is correct
14 Correct 113 ms 39440 KB Output is correct
15 Correct 115 ms 39416 KB Output is correct
16 Correct 112 ms 39512 KB Output is correct
17 Correct 112 ms 39508 KB Output is correct
18 Correct 117 ms 39584 KB Output is correct
19 Correct 114 ms 39508 KB Output is correct
20 Correct 113 ms 39508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29272 KB Output is correct
2 Correct 6 ms 29272 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 5 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 5 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 6 ms 29276 KB Output is correct
10 Correct 5 ms 29276 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 5 ms 29276 KB Output is correct
13 Correct 6 ms 29312 KB Output is correct
14 Correct 6 ms 29272 KB Output is correct
15 Correct 5 ms 29272 KB Output is correct
16 Correct 5 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 5 ms 29276 KB Output is correct
19 Correct 5 ms 29276 KB Output is correct
20 Correct 5 ms 29284 KB Output is correct
21 Correct 21 ms 29276 KB Output is correct
22 Correct 21 ms 29272 KB Output is correct
23 Correct 19 ms 29276 KB Output is correct
24 Correct 19 ms 29276 KB Output is correct
25 Correct 19 ms 29276 KB Output is correct
26 Correct 19 ms 29276 KB Output is correct
27 Correct 19 ms 29376 KB Output is correct
28 Correct 19 ms 29276 KB Output is correct
29 Correct 19 ms 29376 KB Output is correct
30 Correct 20 ms 29276 KB Output is correct
31 Correct 20 ms 29276 KB Output is correct
32 Correct 20 ms 29276 KB Output is correct
33 Correct 21 ms 29364 KB Output is correct
34 Correct 20 ms 29276 KB Output is correct
35 Correct 20 ms 29276 KB Output is correct
36 Correct 20 ms 29376 KB Output is correct
37 Correct 20 ms 29276 KB Output is correct
38 Correct 20 ms 29276 KB Output is correct
39 Correct 20 ms 29372 KB Output is correct
40 Correct 20 ms 29372 KB Output is correct
41 Correct 21 ms 29272 KB Output is correct
42 Correct 20 ms 29276 KB Output is correct
43 Correct 21 ms 29276 KB Output is correct
44 Correct 22 ms 29376 KB Output is correct
45 Correct 20 ms 29376 KB Output is correct
46 Correct 21 ms 29272 KB Output is correct
47 Correct 21 ms 29276 KB Output is correct
48 Correct 26 ms 29272 KB Output is correct
49 Correct 21 ms 29276 KB Output is correct
50 Correct 21 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29272 KB Output is correct
2 Correct 6 ms 29272 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 5 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 5 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 6 ms 29276 KB Output is correct
10 Correct 5 ms 29276 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 5 ms 29276 KB Output is correct
13 Correct 6 ms 29312 KB Output is correct
14 Correct 6 ms 29272 KB Output is correct
15 Correct 5 ms 29272 KB Output is correct
16 Correct 5 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 5 ms 29276 KB Output is correct
19 Correct 5 ms 29276 KB Output is correct
20 Correct 5 ms 29284 KB Output is correct
21 Correct 118 ms 39564 KB Output is correct
22 Correct 113 ms 39564 KB Output is correct
23 Correct 117 ms 39340 KB Output is correct
24 Correct 115 ms 39764 KB Output is correct
25 Correct 112 ms 39504 KB Output is correct
26 Correct 109 ms 39504 KB Output is correct
27 Correct 111 ms 39508 KB Output is correct
28 Correct 115 ms 39512 KB Output is correct
29 Correct 115 ms 39564 KB Output is correct
30 Correct 110 ms 39508 KB Output is correct
31 Correct 119 ms 39508 KB Output is correct
32 Correct 116 ms 39440 KB Output is correct
33 Correct 117 ms 39808 KB Output is correct
34 Correct 113 ms 39440 KB Output is correct
35 Correct 115 ms 39416 KB Output is correct
36 Correct 112 ms 39512 KB Output is correct
37 Correct 112 ms 39508 KB Output is correct
38 Correct 117 ms 39584 KB Output is correct
39 Correct 114 ms 39508 KB Output is correct
40 Correct 113 ms 39508 KB Output is correct
41 Correct 21 ms 29276 KB Output is correct
42 Correct 21 ms 29272 KB Output is correct
43 Correct 19 ms 29276 KB Output is correct
44 Correct 19 ms 29276 KB Output is correct
45 Correct 19 ms 29276 KB Output is correct
46 Correct 19 ms 29276 KB Output is correct
47 Correct 19 ms 29376 KB Output is correct
48 Correct 19 ms 29276 KB Output is correct
49 Correct 19 ms 29376 KB Output is correct
50 Correct 20 ms 29276 KB Output is correct
51 Correct 20 ms 29276 KB Output is correct
52 Correct 20 ms 29276 KB Output is correct
53 Correct 21 ms 29364 KB Output is correct
54 Correct 20 ms 29276 KB Output is correct
55 Correct 20 ms 29276 KB Output is correct
56 Correct 20 ms 29376 KB Output is correct
57 Correct 20 ms 29276 KB Output is correct
58 Correct 20 ms 29276 KB Output is correct
59 Correct 20 ms 29372 KB Output is correct
60 Correct 20 ms 29372 KB Output is correct
61 Correct 21 ms 29272 KB Output is correct
62 Correct 20 ms 29276 KB Output is correct
63 Correct 21 ms 29276 KB Output is correct
64 Correct 22 ms 29376 KB Output is correct
65 Correct 20 ms 29376 KB Output is correct
66 Correct 21 ms 29272 KB Output is correct
67 Correct 21 ms 29276 KB Output is correct
68 Correct 26 ms 29272 KB Output is correct
69 Correct 21 ms 29276 KB Output is correct
70 Correct 21 ms 29276 KB Output is correct
71 Correct 5 ms 29276 KB Output is correct
72 Correct 5 ms 29276 KB Output is correct
73 Correct 1354 ms 39592 KB Output is correct
74 Correct 1353 ms 49028 KB Output is correct
75 Correct 1342 ms 49012 KB Output is correct
76 Correct 1335 ms 48968 KB Output is correct
77 Correct 1332 ms 48972 KB Output is correct
78 Correct 1378 ms 48688 KB Output is correct
79 Correct 1362 ms 48724 KB Output is correct
80 Correct 1388 ms 48800 KB Output is correct
81 Correct 1376 ms 48692 KB Output is correct
82 Correct 1371 ms 48776 KB Output is correct
83 Correct 1444 ms 48272 KB Output is correct
84 Correct 1463 ms 48128 KB Output is correct
85 Correct 1453 ms 48128 KB Output is correct
86 Correct 1433 ms 48124 KB Output is correct
87 Correct 1437 ms 48120 KB Output is correct
88 Correct 1504 ms 47524 KB Output is correct
89 Correct 1502 ms 47552 KB Output is correct
90 Correct 1526 ms 47520 KB Output is correct
91 Correct 1495 ms 47488 KB Output is correct
92 Correct 1502 ms 47532 KB Output is correct
93 Correct 1552 ms 47152 KB Output is correct
94 Correct 1552 ms 47152 KB Output is correct
95 Correct 1537 ms 47156 KB Output is correct
96 Correct 1551 ms 47160 KB Output is correct
97 Correct 1538 ms 47188 KB Output is correct
98 Correct 1343 ms 48872 KB Output is correct
99 Correct 1341 ms 48924 KB Output is correct
100 Correct 1340 ms 48924 KB Output is correct
101 Correct 1593 ms 46652 KB Output is correct
102 Correct 1600 ms 46652 KB Output is correct