답안 #422695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422695 2021-06-10T10:33:32 Z ak2006 Sure Bet (CEOI17_sure) C++14
0 / 100
5 ms 1100 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
int main()
{
    setIO();
    int n;
    cin>>n;
    vector<double>a(n),b(n);
    vector<double>sums(n + 1);
    for (int i = 0;i<n;i++)cin>>a[i]>>b[i],a[i]--,b[i]--;
    sort(a.begin(),a.end()),sort(b.begin(),b.end());
    for (int i = n - 1;i>=0;i--)sums[i] = b[i] + sums[i + 1];
    double sum = 0;
    double out = 0;
    for (int i = n - 1;i>=0;i--){
        int na = n - i;
        sum += a[i];
        int l = 0,r = n - 1,ans = -1;
        while (l <= r){
            int mid = (l + r)/2;
            if (sums[mid] + n - mid >= sum + na){
                ans = mid;
                l = mid + 1;
            }
            else r = mid - 1;
        }
        if (ans == -1){
            double val = sums[0] - na;
            out = max(out,val);
        }
        else {
            double val = sum - (n - ans);
            out = max(out,val);
        }
    }
    printf("%.4lf\n", out);
    return 0;
}

Compilation message

sure.cpp: In function 'void setIO()':
sure.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen("input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen("output.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -