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 <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
int n;
ld a[100009], b[100009];
int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n;
for(int i = 0; i < n; ++i){
scanf("%Lf", &a[i]);
scanf("%Lf", &b[i]);
}
sort(a, a+n, greater<ld>());
sort(b, b+n, greater<ld>());
ld ans = 0;
ld aProfit = 0;
int aIndex = 0;
ld bProfit = 0;
int bIndex = 0;
int spent = 0;
while(aIndex < n || bIndex < n){
spent += 1;
if(aIndex < n && (bIndex >= n || aProfit < bProfit)){
aProfit += a[aIndex++];
} else{
bProfit += b[bIndex++];
}
ans = max(ans, min(aProfit, bProfit)-spent);
}
printf("%.4lf", (double)ans);
}
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%Lf", &a[i]);
| ~~~~~^~~~~~~~~~~~~~
sure.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%Lf", &b[i]);
| ~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |