답안 #991955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991955 2024-06-03T12:55:32 Z mannshah1211 Gym Badges (NOI22_gymbadges) C++14
100 / 100
127 ms 6544 KB
/**
 *    author: tourist
 *    created:
**/
#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#if 1
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
  }
  sort(a.begin(), a.end(), [&](pair<int, int> &x, pair<int, int> &y) {
    if (x.first + x.second == y.first + y.second) {
      return (x.first < y.first);
    }
    return (x.first + x.second < y.first + y.second);
  });
  long long tot = 0;
  priority_queue<int> taken;
  for (int i = 0; i < n; i++) {
    if (tot <= a[i].second) {
      taken.push(a[i].first);
      tot += a[i].first;
      continue;
    }
    if (taken.top() <= a[i].first) {
      continue;
    }
    if (tot - taken.top() <= a[i].second) {
      tot -= taken.top();
      taken.pop();
      tot += a[i].first;
      taken.push(a[i].first);
    }
  }
  cout << taken.size() << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 4188 KB Output is correct
2 Correct 105 ms 4352 KB Output is correct
3 Correct 121 ms 4188 KB Output is correct
4 Correct 103 ms 4184 KB Output is correct
5 Correct 103 ms 4184 KB Output is correct
6 Correct 101 ms 4436 KB Output is correct
7 Correct 96 ms 4376 KB Output is correct
8 Correct 103 ms 4432 KB Output is correct
9 Correct 104 ms 4432 KB Output is correct
10 Correct 99 ms 4436 KB Output is correct
11 Correct 95 ms 5512 KB Output is correct
12 Correct 94 ms 6532 KB Output is correct
13 Correct 121 ms 5508 KB Output is correct
14 Correct 97 ms 6348 KB Output is correct
15 Correct 95 ms 6348 KB Output is correct
16 Correct 108 ms 4824 KB Output is correct
17 Correct 100 ms 4824 KB Output is correct
18 Correct 102 ms 4820 KB Output is correct
19 Correct 97 ms 4692 KB Output is correct
20 Correct 99 ms 4604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 2 ms 344 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 2 ms 344 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 120 ms 4188 KB Output is correct
22 Correct 105 ms 4352 KB Output is correct
23 Correct 121 ms 4188 KB Output is correct
24 Correct 103 ms 4184 KB Output is correct
25 Correct 103 ms 4184 KB Output is correct
26 Correct 101 ms 4436 KB Output is correct
27 Correct 96 ms 4376 KB Output is correct
28 Correct 103 ms 4432 KB Output is correct
29 Correct 104 ms 4432 KB Output is correct
30 Correct 99 ms 4436 KB Output is correct
31 Correct 95 ms 5512 KB Output is correct
32 Correct 94 ms 6532 KB Output is correct
33 Correct 121 ms 5508 KB Output is correct
34 Correct 97 ms 6348 KB Output is correct
35 Correct 95 ms 6348 KB Output is correct
36 Correct 108 ms 4824 KB Output is correct
37 Correct 100 ms 4824 KB Output is correct
38 Correct 102 ms 4820 KB Output is correct
39 Correct 97 ms 4692 KB Output is correct
40 Correct 99 ms 4604 KB Output is correct
41 Correct 2 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 492 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 2 ms 348 KB Output is correct
62 Correct 2 ms 348 KB Output is correct
63 Correct 2 ms 348 KB Output is correct
64 Correct 2 ms 344 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 2 ms 344 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 123 ms 4372 KB Output is correct
74 Correct 108 ms 4360 KB Output is correct
75 Correct 108 ms 4372 KB Output is correct
76 Correct 105 ms 4356 KB Output is correct
77 Correct 103 ms 4188 KB Output is correct
78 Correct 108 ms 5004 KB Output is correct
79 Correct 107 ms 4824 KB Output is correct
80 Correct 106 ms 5000 KB Output is correct
81 Correct 108 ms 4760 KB Output is correct
82 Correct 115 ms 4824 KB Output is correct
83 Correct 107 ms 5508 KB Output is correct
84 Correct 108 ms 5332 KB Output is correct
85 Correct 108 ms 5332 KB Output is correct
86 Correct 107 ms 5328 KB Output is correct
87 Correct 125 ms 5328 KB Output is correct
88 Correct 127 ms 6352 KB Output is correct
89 Correct 107 ms 6528 KB Output is correct
90 Correct 107 ms 6352 KB Output is correct
91 Correct 108 ms 6348 KB Output is correct
92 Correct 105 ms 6348 KB Output is correct
93 Correct 106 ms 6544 KB Output is correct
94 Correct 105 ms 6532 KB Output is correct
95 Correct 105 ms 6356 KB Output is correct
96 Correct 106 ms 6348 KB Output is correct
97 Correct 107 ms 6352 KB Output is correct
98 Correct 108 ms 4432 KB Output is correct
99 Correct 105 ms 4436 KB Output is correct
100 Correct 108 ms 4376 KB Output is correct
101 Correct 104 ms 6352 KB Output is correct
102 Correct 109 ms 6536 KB Output is correct