Submission #1117839

# Submission time Handle Problem Language Result Execution time Memory
1117839 2024-11-24T08:49:29 Z vjudge1 Sure Bet (CEOI17_sure) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>

using namespace std;

#define TASK "sure"
#define REP(i, n) for(int i = 1; i <= n; i++)
#define FOR(i, a, b) for(auto i = a; i <= b; i++)
#define FORD(i, a, b) for(auto i = a; i >= b; i--)
template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; }
template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; }

const int N = (int)1e5 + 7;

double a[N], b[N];
int n;

void Read()
{
    scanf("%d", &n);
    REP(i, n)
        scanf("%lf %lf", &a[i], &b[i]);
}

priority_queue<double, vector<double>, greater<double> > pq[2];

void Solve()
{
    int c = 0;
    double pA = 0, pB = 0;
    REP(i, n)
    {
        c += 2;
        pq[0].push(a[i]);
        pq[1].push(b[i]);
        pA += a[i];
        pB += b[i];
    }
    double ans = min(pA - c, pB - c);
    while(pq[0].size() && pq[1].size())
    {
        c--;
        double val1 = pq[0].top();
        double val2 = pq[1].top();
        if(pA - val1 < pB - val2)
        {
            pq[1].pop();
            pB -= val2;
        }
        else
        {
            pA -= val1;
            pq[0].pop();
        }
//        printf("%.4lf %.4lf %d\n", pA, pB, c);
        maximize(ans, min(pA - c * 1.0, pB - c * 1.0));
    }
    printf("%.4lf", ans);
}

signed main()
{
    cin.tie(0)->ios_base::sync_with_stdio(0);

    if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
    if(fopen(TASK".INP", "r")) {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }

    Read();
    Solve();

    return 0;
}
/*
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
*/

Compilation message

sure.cpp: In function 'void Read()':
sure.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
sure.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%lf %lf", &a[i], &b[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp: In function 'int main()':
sure.cpp:64:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -