답안 #800972

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800972 2023-08-02T03:18:30 Z vjudge1 Sure Bet (CEOI17_sure) C++11
100 / 100
89 ms 3448 KB
#include <bits/stdc++.h>
#define taskname "surebet"
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef unsigned long long ull;
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define es erase
#define is insert
#define all(x) x.begin(), x.end()
#define EL printf("\n")
#define sz(A) (int) A.size()
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define FOD(i,r,l) for (int i=r;i>=l;i--)
#define fillchar(a,x) memset(a, x, sizeof (a))
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("Os")
//#pragma GCC target ("avx2")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
priority_queue <int,vector<int>,greater<int> > pq;
int n ;
const int maxn = 1e5+13;
long double a[maxn], b[maxn];
bool cmp (int x , int y)
{
    return x > y;
}
void readInput()
{
    cin>>n;
    for(int i=1 ; i<=n ; ++i) cin>>a[i]>>b[i];
    sort(a+1, a+1+n );
    sort(b+1, b+1+n );
    bool ok = false;
    long double ans = 0;
    int cnt = 0;
    long double suma = 0;
    long double sumb = 0;
    int k1 = n;
    int k2 = n;
    while(true)
    {
        if(k1 == 0 && k2 == 0) break;
        if(k1 == 0)
        {
            sumb += b[k2];
            k2--;
            cnt++;
        }
        else if(k2 == 0)
        {
             suma += a[k1];
            k1--;
            cnt++;
        }
        else if(suma<sumb )
        {
            suma += a[k1];
            k1--;
            cnt++;
        }
        else if( suma > sumb)
        {
            sumb += b[k2];
            k2--;
            cnt++;
        }
        else if(suma == sumb)
        {
            if(k2 == 0 || a[k1] > b[k2])
            {
                suma += a[k1];
                k1--;
                cnt++;
            }
            else if(k1 == 0 || a[k1] <= b[k2])
            {
                sumb += b[k2];
                k2--;
                cnt++;
            }
        }
        long double res = min(suma - cnt , sumb - cnt);
        ans = max(ans , res);
    }
    cout<<fixed << setprecision(4) <<ans;
}
void init()
{
 
}
void solve()
{
 
}
void print()
{
 
}
int main()
{
    faster
//    freopen(taskname".INP","r",stdin);
//    freopen(taskname".OUT","w",stdout);
    readInput();
    solve();
    print();
    return 0;
}
/* test
 
 
 
 
 
 
 
*/

Compilation message

sure.cpp: In function 'void readInput()':
sure.cpp:40:10: warning: unused variable 'ok' [-Wunused-variable]
   40 |     bool ok = false;
      |          ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 75 ms 3412 KB Output is correct
18 Correct 75 ms 3448 KB Output is correct
19 Correct 72 ms 3360 KB Output is correct
20 Correct 72 ms 3440 KB Output is correct
21 Correct 89 ms 3392 KB Output is correct
22 Correct 71 ms 3444 KB Output is correct
23 Correct 71 ms 3448 KB Output is correct
24 Correct 72 ms 3444 KB Output is correct
25 Correct 71 ms 3404 KB Output is correct
26 Correct 75 ms 3448 KB Output is correct