답안 #1028288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028288 2024-07-19T15:50:29 Z vjudge1 Sure Bet (CEOI17_sure) C++17
100 / 100
71 ms 5224 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("popcnt")
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fo(i,n) for(auto i =0 ; i < n;i++)
#define fore(i,l,r) for(auto i = l; i < r;i++)
#define forex(i,r,l) for(auto i = r; i >= l; i--)
#define ffo(i,n) forex(i,n-1,0)
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define sz(x) (int)x.size()
#define gcd(a,b) __gcd(a,b)
#define vii vector<ii>
#define pq_min(a) priority_queue<a, vector<a>, greater<a>>
#define fls cout.flush()
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using ii = pair<int,int>;
using mii = map<int,int>;
using lld = long double;
void valid(ll in){cout<<((in)?"YES\n":"NO\n");}
void test_case(){
    int n;
    cin >> n;
    lld a[n]{}, b[n]{};
    fo(i,n)cin >> a[i] >> b[i];
    sort(a,a+n);
    sort(b,b+n);
    lld ans = 0;
    lld sa = 0;
    lld sb = 0, best = 0;
    int l = 0;
    for(int i = 0; i <= n; i++){
        if(i)sa += a[n-i];
        // fijamos min en sb
        while(l<n&&sb+b[n-l-1]<=sa){
            sb+=b[n-l-1],l++;
            best = max(best, sb - l);
        }
        ans = max(ans, best - i);
        if(l<n-1){
            ans = max(ans, sa - i - l - 1);
        }
    }
    cout << ans << endl;
}
int main(){cin.tie(0)->sync_with_stdio(0);
    cout<<setprecision(4)<<fixed;
    int t=1;
    // cin >> t;
    while(t--)test_case();
}

Compilation message

sure.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("O3")
      | 
sure.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 420 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 420 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 420 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 67 ms 4860 KB Output is correct
18 Correct 66 ms 4948 KB Output is correct
19 Correct 70 ms 4692 KB Output is correct
20 Correct 67 ms 4948 KB Output is correct
21 Correct 71 ms 5224 KB Output is correct
22 Correct 66 ms 4848 KB Output is correct
23 Correct 65 ms 4952 KB Output is correct
24 Correct 65 ms 4724 KB Output is correct
25 Correct 65 ms 4948 KB Output is correct
26 Correct 68 ms 5200 KB Output is correct