이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define optimus_prime ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fxd(x) fixed << setprecision(x)
#define all(a) (a.begin() , a.end())
#define popcount(x) __builtin_popcount(x)
#define lwb lower_bound
#define upb upper_bound
#define dl long double
#define ll long long
#define pb push_back
#define sz() size()
#define F first
#define S second
using namespace std;
const ll N = 2e5+9;
ll n;
dl a[N] , b[N] , zr=0;
dl calc(ll cnt){
ll ind1=1 , ind2=1 , i=cnt;
dl sum1=0 , sum2=0;
while (cnt){
cnt--;
if (ind1>n){
sum2+=b[ind2];
ind2++;
continue;
}
if (ind2>n){
sum1+=a[ind1];
ind1++;
continue;
}
if (sum1<sum2)sum1+=a[ind1++];
else if (sum1>sum2)sum2+=b[ind2++];
else {
if (a[ind1]>b[ind2])sum1+=a[ind1++];
else sum2+=(b[ind2++]);
}
}
sum1-=i;
sum2-=i;
return min(sum1 , sum2);
}
void solve(){
cin >> n;
for (int i = 1 ; i <= n ; i++)cin >> a[i] >> b[i];
sort (a+1 , a+1+n);
sort (b+1 , b+1+n);
reverse (a+1 , a+1+n);
reverse (b+1 , b+1+n);
ll l=1 , r=2*n , res=0;
while (l<=r){
ll md1=l+(r-l)/3;
ll md2=r-(r-l)/3;
dl sum1=calc(md1);
dl sum2=calc(md2);
if (sum1<sum2)l=md1+1 , res=md2;
else r=md2-1 , res=md1;
}
dl ans=max({calc(n/2) , calc(n/2+1) , zr});
cout << fxd(4) << ans;
}
signed main() {
optimus_prime;
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sure.cpp: In function 'void solve()':
sure.cpp:58:19: warning: variable 'res' set but not used [-Wunused-but-set-variable]
58 | ll l=1 , r=2*n , res=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... |