답안 #998303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998303 2024-06-13T14:52:03 Z cpptowin Gym Badges (NOI22_gymbadges) C++17
9 / 100
145 ms 18924 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 < b.fi or (a.fi == b.fi and a.se < b.se);
    });
    // fo(i,1,n) cout << a[i].fi << ' ' << a[i].se << "\n";
    priority_queue<int> q;
    int sum = 0;
    int ans = 0;
    int now = 0;
    int tot = 0;
    fo(i,1,n)
    {
        vi v;
        while(q.size() and sum > a[i].fi)
        {
            sum -= q.top();
            v.pb(q.top());
            q.pop();
            now--;
        } 
        now++;
        q.push(a[i].se);
        sum += a[i].se;
        if(ans < now or (ans == now and tot < sum))
        {
            ans = now;
            tot = sum;
        }
        else 
        {
            for(int it : v) sum += it,q.push(it);
            sum -= a[i].se;
        }
    }
    cout << ans;
}

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 13944 KB Output is correct
2 Correct 125 ms 13652 KB Output is correct
3 Correct 120 ms 13648 KB Output is correct
4 Correct 119 ms 13660 KB Output is correct
5 Correct 129 ms 13756 KB Output is correct
6 Correct 130 ms 14288 KB Output is correct
7 Correct 126 ms 14036 KB Output is correct
8 Correct 134 ms 14120 KB Output is correct
9 Correct 127 ms 14096 KB Output is correct
10 Correct 133 ms 15568 KB Output is correct
11 Correct 113 ms 18300 KB Output is correct
12 Correct 110 ms 18924 KB Output is correct
13 Correct 112 ms 18808 KB Output is correct
14 Correct 113 ms 18632 KB Output is correct
15 Correct 133 ms 17612 KB Output is correct
16 Correct 145 ms 18416 KB Output is correct
17 Correct 142 ms 17096 KB Output is correct
18 Correct 140 ms 17352 KB Output is correct
19 Correct 144 ms 17864 KB Output is correct
20 Correct 142 ms 17096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -