답안 #298991

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298991 2020-09-14T11:50:43 Z jbroeksteeg Sure Bet (CEOI17_sure) C++14
100 / 100
114 ms 5480 KB
#include <iostream>
#include <climits>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <array>
#include <memory>

#define IN(a,b) (a.find(b) != a.end())
#define p(a,b) make_pair(a,b)
#define readVec(a) for (int __i = 0; __i<(int)a.size();__i++){cin>>a[__i];}

// jimjam

template<typename T>
void pMin(T &a, T b) {if (b<a){a=b;}}
template<typename T>
void pMax(T &a, T b) {if (b>a){a=b;}}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c);
template<typename A, typename B>
std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) {
	if (c.size() == 0) {os << "{}"; return os;}
	os << "{" << c[0];
	for (int i = 1; i < (int)c.size(); i++) {os <<", "<<c[i];}
	os << "}";
	return os;
}

const int inf = 2e9;

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n; cin >> n;
	vector<pair<double,double>> people(n);
	
	vector<double> first, second;
	for (int i = 0; i < n; i++) {
		cin >> people[i].first >> people[i].second;
		first.push_back(people[i].first);
		second.push_back(people[i].second);
	}
	sort(first.begin(),first.end());
	sort(second.begin(),second.end());
	reverse(first.begin(),first.end());
	reverse(second.begin(),second.end());
	
	double ans = 0; // even
	
	double lSum=0,rSum=0;
	int l=0,r=0;
	while (l!=n||r!=n) {
		bool canFirst=l<n, canSecond=r<n;
		if (canFirst && canSecond) {
			if (lSum<=rSum) {
				lSum += first[l++];
			} else {
				rSum += second[r++];
			}
		} else if (canFirst) {
			lSum += first[l++]; 
		} else if (canSecond) {
			rSum += second[r++];	
		} else {
			assert(false);
		}
		pMax(ans, min(lSum, rSum) - l - r);
	}

	printf("%.4lf\n", (double)ans);
	
	return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 93 ms 3692 KB Output is correct
18 Correct 98 ms 5092 KB Output is correct
19 Correct 96 ms 5076 KB Output is correct
20 Correct 96 ms 5092 KB Output is correct
21 Correct 102 ms 5476 KB Output is correct
22 Correct 98 ms 5080 KB Output is correct
23 Correct 95 ms 5200 KB Output is correct
24 Correct 114 ms 5092 KB Output is correct
25 Correct 96 ms 5092 KB Output is correct
26 Correct 104 ms 5480 KB Output is correct