This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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.0;
for (int i = 0; i < n; i++) {
lSum+=first[i];
double rSum=0.0;
for (int j = 0; j < n; j++) {
rSum+=second[j];
pMax(ans, min(lSum,rSum)-double(i+1 + j+1));
}
}
printf("%.4lf\n", (double)ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |