Submission #931454

# Submission time Handle Problem Language Result Execution time Memory
931454 2024-02-21T20:35:50 Z vjudge1 Gym Badges (NOI22_gymbadges) C++17
24 / 100
131 ms 39596 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 5e5+5, S = 2, 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 6 ms 29276 KB Output is correct
2 Correct 5 ms 29276 KB Output is correct
3 Correct 5 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 5 ms 29272 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 29308 KB Output is correct
9 Correct 7 ms 29280 KB Output is correct
10 Correct 6 ms 29272 KB Output is correct
11 Correct 6 ms 29272 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 7 ms 29528 KB Output is correct
15 Correct 5 ms 29328 KB Output is correct
16 Correct 6 ms 29272 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 5 ms 29324 KB Output is correct
19 Correct 6 ms 29276 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 39504 KB Output is correct
2 Correct 114 ms 39504 KB Output is correct
3 Correct 114 ms 39508 KB Output is correct
4 Correct 128 ms 39504 KB Output is correct
5 Correct 116 ms 39508 KB Output is correct
6 Correct 123 ms 39572 KB Output is correct
7 Correct 109 ms 39544 KB Output is correct
8 Correct 129 ms 39508 KB Output is correct
9 Correct 114 ms 39572 KB Output is correct
10 Correct 116 ms 39572 KB Output is correct
11 Correct 115 ms 39552 KB Output is correct
12 Correct 114 ms 39504 KB Output is correct
13 Correct 116 ms 39512 KB Output is correct
14 Correct 126 ms 39572 KB Output is correct
15 Correct 115 ms 39504 KB Output is correct
16 Correct 121 ms 39504 KB Output is correct
17 Correct 126 ms 39596 KB Output is correct
18 Correct 118 ms 39504 KB Output is correct
19 Correct 117 ms 39504 KB Output is correct
20 Correct 131 ms 39504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29276 KB Output is correct
2 Correct 5 ms 29276 KB Output is correct
3 Correct 5 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 5 ms 29272 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 29308 KB Output is correct
9 Correct 7 ms 29280 KB Output is correct
10 Correct 6 ms 29272 KB Output is correct
11 Correct 6 ms 29272 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 7 ms 29528 KB Output is correct
15 Correct 5 ms 29328 KB Output is correct
16 Correct 6 ms 29272 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 5 ms 29324 KB Output is correct
19 Correct 6 ms 29276 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Incorrect 7 ms 29276 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29276 KB Output is correct
2 Correct 5 ms 29276 KB Output is correct
3 Correct 5 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 5 ms 29272 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 29308 KB Output is correct
9 Correct 7 ms 29280 KB Output is correct
10 Correct 6 ms 29272 KB Output is correct
11 Correct 6 ms 29272 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 7 ms 29528 KB Output is correct
15 Correct 5 ms 29328 KB Output is correct
16 Correct 6 ms 29272 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 5 ms 29324 KB Output is correct
19 Correct 6 ms 29276 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 114 ms 39504 KB Output is correct
22 Correct 114 ms 39504 KB Output is correct
23 Correct 114 ms 39508 KB Output is correct
24 Correct 128 ms 39504 KB Output is correct
25 Correct 116 ms 39508 KB Output is correct
26 Correct 123 ms 39572 KB Output is correct
27 Correct 109 ms 39544 KB Output is correct
28 Correct 129 ms 39508 KB Output is correct
29 Correct 114 ms 39572 KB Output is correct
30 Correct 116 ms 39572 KB Output is correct
31 Correct 115 ms 39552 KB Output is correct
32 Correct 114 ms 39504 KB Output is correct
33 Correct 116 ms 39512 KB Output is correct
34 Correct 126 ms 39572 KB Output is correct
35 Correct 115 ms 39504 KB Output is correct
36 Correct 121 ms 39504 KB Output is correct
37 Correct 126 ms 39596 KB Output is correct
38 Correct 118 ms 39504 KB Output is correct
39 Correct 117 ms 39504 KB Output is correct
40 Correct 131 ms 39504 KB Output is correct
41 Incorrect 7 ms 29276 KB Output isn't correct
42 Halted 0 ms 0 KB -