답안 #865381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865381 2023-10-24T07:47:43 Z vjudge1 Sure Bet (CEOI17_sure) C++17
60 / 100
66 ms 2212 KB
//Bismillahir-Rahmanir-Rahim
#include <bits/stdc++.h>
         
using namespace std;
      
#define flash ios_base::sync_with_stdio(0),cin.tie(0)
#define pb push_back
#define ll long long
#define ld long double
#define dbg(x) cerr << #x << " = " << x << "\n";
#define ff first
#define ss second
 
 /*     
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma comment (linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/ 
 
const long long INF = 1e9 + 7;
const long long MOD = 1e9 + 7;
const int maxn = 1e5 + 10;

int n;
double a[maxn], b[maxn], ans, x, y, sz, ans2;

void press_F_() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		// a[i] = rand() % 1000 + 1;
		// b[i] = rand() % 1000 + 1;
	}
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	reverse(a + 1, a + n + 1);
	reverse(b + 1, b + n + 1);
	int id1 = 0, id2 = 0;
	// return;
	if (n <= 1000) {
		x = 0;
		y = 0;
		for (int i = 0; i <= n; i++) {
			y = 0;
			x += a[i];
			for (int j = 0; j <= n; j++) {
				y += b[j];
				ans2 = max(ans2, min(x - i - j, y - i - j));
			}
		}
		printf("%.4lf",(double)ans2);
		return;
	}
	while(id1 < n || id2 < n) {
		if (min(x + a[id1 + 1] - (sz + 1), y - (sz + 1)) >= min(x - (sz + 1), y + b[id2 + 1] - (sz + 1))) {
			id1++;
			x += a[id1];
			sz++;
		} else {
			id2++;
			y += b[id2];
			sz++;
		}
		ans = max(ans, min(x - sz, y - sz));
	}
	
	printf("%.4lf",(double)ans);
	// cout << '\n';
	
} 

int main() {
    flash;
    srand(time(0));
    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++) {
        // cout << "Case" << " " << i << ':' << "\n";
        press_F_();
    }
    //Respa gold 2023-2024 InshAllah
    return 0;
}
/*
Maybe not today and tomorrow, but InshAllah one day I will reach expert
*/
// g++ -std=c++17 main.cpp
// ./a.out
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 480 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 480 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 63 ms 2212 KB Output is correct
18 Correct 66 ms 1868 KB Output is correct
19 Correct 58 ms 1944 KB Output is correct
20 Incorrect 57 ms 1872 KB Output isn't correct
21 Halted 0 ms 0 KB -