# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1117854 | 2024-11-24T08:58:00 Z | vjudge1 | Sure Bet (CEOI17_sure) | C++17 | 63 ms | 5444 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(); } maximize(ans, min(pA - c * 1.0, pB - c * 1.0)); } while(pq[0].size()) { c--; pA -= pq[0].top(); pq[0].pop(); maximize(ans, min(pA - c * 1.0, pB - c * 1.0)); } while(pq[1].size()) { c--; pB -= pq[1].top(); pq[1].pop(); 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 2 ms | 504 KB | Output is correct |
13 | Correct | 2 ms | 700 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 2 ms | 336 KB | Output is correct |
16 | Correct | 2 ms | 508 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 2 ms | 504 KB | Output is correct |
13 | Correct | 2 ms | 700 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 2 ms | 336 KB | Output is correct |
16 | Correct | 2 ms | 508 KB | Output is correct |
17 | Correct | 61 ms | 5088 KB | Output is correct |
18 | Correct | 54 ms | 5052 KB | Output is correct |
19 | Correct | 62 ms | 5052 KB | Output is correct |
20 | Correct | 54 ms | 5052 KB | Output is correct |
21 | Correct | 59 ms | 5308 KB | Output is correct |
22 | Correct | 56 ms | 5036 KB | Output is correct |
23 | Correct | 55 ms | 5052 KB | Output is correct |
24 | Correct | 55 ms | 5052 KB | Output is correct |
25 | Correct | 54 ms | 5052 KB | Output is correct |
26 | Correct | 63 ms | 5444 KB | Output is correct |