Submission #998325

# Submission time Handle Problem Language Result Execution time Memory
998325 2024-06-13T15:45:45 Z cpptowin Gym Badges (NOI22_gymbadges) C++17
100 / 100
144 ms 22892 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(),x.end()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
int n;
pii a[maxn];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    fo(i,1,n) cin >> a[i].se;
    fo(i,1,n) cin >> a[i].fi;
    sort(a + 1,a + n + 1,[](pii a,pii b)
    {
        return a.fi + a.se < b.fi + b.se or (a.fi + a.se == b.fi + b.se and a.se < b.se);
    });
    int sum = 0;
    priority_queue<int> q;
    fo(i,1,n)
    {
        if(sum <= a[i].fi)
        {
            q.push(a[i].se);
            sum += a[i].se;
        }
        else 
        {
            if(q.size() and q.top() > a[i].se)
            {
                sum -= q.top();
                sum += a[i].se;
                q.pop();
                q.push(a[i].se);
            }
        }
    }
    cout << q.size();
}

Compilation message

Main.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 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 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 98 ms 8836 KB Output is correct
2 Correct 117 ms 13612 KB Output is correct
3 Correct 108 ms 13852 KB Output is correct
4 Correct 111 ms 13744 KB Output is correct
5 Correct 122 ms 13940 KB Output is correct
6 Correct 104 ms 13712 KB Output is correct
7 Correct 99 ms 13136 KB Output is correct
8 Correct 122 ms 13484 KB Output is correct
9 Correct 112 ms 13740 KB Output is correct
10 Correct 104 ms 13752 KB Output is correct
11 Correct 133 ms 14952 KB Output is correct
12 Correct 93 ms 17676 KB Output is correct
13 Correct 94 ms 14920 KB Output is correct
14 Correct 92 ms 18132 KB Output is correct
15 Correct 96 ms 18372 KB Output is correct
16 Correct 99 ms 14336 KB Output is correct
17 Correct 98 ms 14312 KB Output is correct
18 Correct 108 ms 14292 KB Output is correct
19 Correct 99 ms 13812 KB Output is correct
20 Correct 106 ms 13820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 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 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 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 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 2 ms 632 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 580 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 1 ms 476 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 628 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 2 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 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 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 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 98 ms 8836 KB Output is correct
22 Correct 117 ms 13612 KB Output is correct
23 Correct 108 ms 13852 KB Output is correct
24 Correct 111 ms 13744 KB Output is correct
25 Correct 122 ms 13940 KB Output is correct
26 Correct 104 ms 13712 KB Output is correct
27 Correct 99 ms 13136 KB Output is correct
28 Correct 122 ms 13484 KB Output is correct
29 Correct 112 ms 13740 KB Output is correct
30 Correct 104 ms 13752 KB Output is correct
31 Correct 133 ms 14952 KB Output is correct
32 Correct 93 ms 17676 KB Output is correct
33 Correct 94 ms 14920 KB Output is correct
34 Correct 92 ms 18132 KB Output is correct
35 Correct 96 ms 18372 KB Output is correct
36 Correct 99 ms 14336 KB Output is correct
37 Correct 98 ms 14312 KB Output is correct
38 Correct 108 ms 14292 KB Output is correct
39 Correct 99 ms 13812 KB Output is correct
40 Correct 106 ms 13820 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 2 ms 632 KB Output is correct
45 Correct 2 ms 600 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 580 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 2 ms 604 KB Output is correct
53 Correct 1 ms 476 KB Output is correct
54 Correct 2 ms 604 KB Output is correct
55 Correct 1 ms 628 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 2 ms 604 KB Output is correct
59 Correct 2 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 2 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 2 ms 604 KB Output is correct
65 Correct 2 ms 604 KB Output is correct
66 Correct 2 ms 604 KB Output is correct
67 Correct 2 ms 604 KB Output is correct
68 Correct 2 ms 604 KB Output is correct
69 Correct 1 ms 604 KB Output is correct
70 Correct 2 ms 472 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 112 ms 18280 KB Output is correct
74 Correct 144 ms 18260 KB Output is correct
75 Correct 113 ms 18296 KB Output is correct
76 Correct 111 ms 18260 KB Output is correct
77 Correct 108 ms 18260 KB Output is correct
78 Correct 111 ms 18900 KB Output is correct
79 Correct 109 ms 19064 KB Output is correct
80 Correct 112 ms 19152 KB Output is correct
81 Correct 109 ms 18932 KB Output is correct
82 Correct 114 ms 19044 KB Output is correct
83 Correct 112 ms 19404 KB Output is correct
84 Correct 123 ms 19668 KB Output is correct
85 Correct 125 ms 19404 KB Output is correct
86 Correct 116 ms 19444 KB Output is correct
87 Correct 110 ms 19436 KB Output is correct
88 Correct 121 ms 21220 KB Output is correct
89 Correct 112 ms 22644 KB Output is correct
90 Correct 124 ms 22892 KB Output is correct
91 Correct 108 ms 20840 KB Output is correct
92 Correct 109 ms 22476 KB Output is correct
93 Correct 111 ms 21192 KB Output is correct
94 Correct 116 ms 21964 KB Output is correct
95 Correct 129 ms 21988 KB Output is correct
96 Correct 109 ms 22472 KB Output is correct
97 Correct 107 ms 21096 KB Output is correct
98 Correct 108 ms 18408 KB Output is correct
99 Correct 105 ms 18544 KB Output is correct
100 Correct 107 ms 18532 KB Output is correct
101 Correct 111 ms 21356 KB Output is correct
102 Correct 109 ms 21476 KB Output is correct