답안 #343253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343253 2021-01-03T15:14:54 Z qwerasdfzxcl Sure Bet (CEOI17_sure) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
ll a[100100];
ll b[100100];
ll bsum[100100];
int n;

ll query(ll val, int ac, int idx){
    ll ret=val-(ll)(idx+ac)*10000, tmp=bsum[idx]-(ll)(idx+ac)*10000;
    //printf("%lld %d %d: %lld\n", val, ac, idx, min(ret, tmp));
    return min(ret, tmp);
}

int psearch(ll val, int ac){
    int l=1, r=n-1, ret=1;
    while(l<=r){
        int m=(l+r)/2;
        if (query(val, ac, m)-query(val, ac, m+1)==10000){
            ret=m;
            r=m-1;
        }
        else l=m+1;
    }
    return ret;
}

int main(){
    scanf("%d", &n);
    for (int i=0;i<n;i++){
        double tmp1, tmp2;
        scanf("%lf %lf", &tmp1, &tmp2);
        a[i]=tmp1*10000;
        b[i]=tmp2*10000;
    }
    sort(a, a+n, greater<int>());
    sort(b, b+n, greater<int>());
    for (int i=0;i<n;i++){
        bsum[i+1]=bsum[i]+b[i];
    }
    ll ans=0, tmp=0;
    if (n<=1010){
        for (int i=0;i<n;i++){
            tmp += a[i];
            for (int j=0;j<=n;j++){
                ans=max(query(tmp, i+1, j), ans);
            }
        }
        printf("%lld.%lld", ans/10000, ans%10000);
        return 0;
    }
    for (int i=0;i<n;i++){
        tmp += a[i];
        int idx=psearch(tmp, i+1);
        ans=max(max(query(tmp, i+1, idx-1), query(tmp, i+1, idx)), ans);
        //printf("%lld %d\n", ans, idx);
    }
    printf("%lld.%lld", ans/10000, ans%10000);
    return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
sure.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |         scanf("%lf %lf", &tmp1, &tmp2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -