/*
........................................````````````````````````.............................-------
...................................````````````````````````````````..........................-------
...................................``````````````````````````````````........--....----......-------
.............................`````````````````````````````...```....--.-.--.-.-.://:.----...--------
...........................````````````````````.``...--..-...`...-:+:--::----//+//--:----...--------
..........................``````````````````..:.....//:+:..-./:.--:/:/.-.//oy+:-./+:----.-----------
........................``````````````````.-.-o+-.--+oo+----/:-:----:::/oo//o:--.+/:-.-::----------:
.......................`.```````````````.--.-:y+-::+o//:./:..-://///+syso+::/::-.::--.:/:-://:--:-::
......................``````````````..-//:---:/-+o+:-:-.--.--++/::oyhsoso///:::------.::--/o:-::::-:
.....................```````````...:+:::-:--:+:-.....-:::://::/+ydhysoo+///:://::---.-----//-/s/:-:+
......................````````--/:-::-----..-----/::///::---/oydhyyoo+++o+/o+/o+://+/:/:--:--/+:--o+
....................```````..--::-:-:--///://+oss+-::-:-....:///////++/oo//:::::/osyyyyyo:/--:/:--+:
....................```````/::/-//++oo+++s+//:/o/--..--..//+oyyyyyyso+//::::::--/:::-:/+osyo/---.::-
....................````..-:-:-:+sso/+/:/:-:o++:--:-//:/+hmNNNmdhyso++/-----//:--::-----::/+ss/:-::-
......................--:::::/+sysy+:::::-:+++ss+o:///+//+oshyyyso++/:::::::/o++o++/o++o::::///os:--
................:-----.:/:/::::////++////++osys++syyhdmmmmdhs+o+://++yhs+hmdmmmNNmddmmNmdsso::--/+ss
................+//:o+o////////:::-::/+//://+oysy+--/ossyhhs+oo+//syyyydhyyysyyyhdddhyyyhdmdyoo+//++
................:ooyy++/::::++///:/yyhmhs:-sdmdo:--+sosssssssoydmddhhhyyyyhhyddddsssooshyyydddhy++//
................./+//o/+oo+o/++smydMMMMNNmmmmho+oosss++syddddhhhhhyyyo+shdmysmMMMmo+hhysoyyyyyhdhhyo
.................:oosyoo//.--ymNMNNMdddysyyyysssshhysssooosysyyyssdmNy+yNNNNmmNMMMNdNNy/+ssyhyysoyys
..................:sys/s..ysdmNmNmmmho///o+syyyyyysysoososyshdNmyomNNNmmNNNNNNNNNNNNMMNo+ysoo+oyysoh
....................-.`.-+mmdddsoo+++osssysooos++++ooyhmmNNmNNhymmmNshNmmmmmNNmmNNNNNNNNdd+++soshmyh
.....................`:-sdhyyyo+soyyso+ooo++ooyo/:/ymNNNNNy:oh.`-+yh--yhsommNmmmmdmmNNNMMMsshsosysyy
....................../so+os+sssoos/+::osoo+/+hNmdhyh+smms````````....:o..+mmdmmmmmdmmmNNMmhdhhsooso
.....................`:oysyyyyyy+/oyhyo+hmmmdyodNN:.:.`/h:```````.........-o/+ymmmmNmmddmNNNN//syoyy
.......................oyysooysmy:/so:////....`-+s-``````.``````..........----yhhhddmNNmdmNNMh/hhs+o
......................../ydd//:-```.``````````````````````````...........-----:yyhmmmmmNmmmmmNyNNy::
..........................+o.```````````````````````````````...........-------:so/yNNmmmmdNNNNNNMMd/
............................```````````````````````````````...........--------:/:::ohdmmNmmmmNNNNNMN
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define sz size()
#define inf 10e9
#define sp " "
#define space cout<<"\n"
#define begin begin()
#define end end()
#define ndl cout<<endl
#define rend rend()
#define rbegin rbegin()
#define pb push_back
#define ender return 0;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define YESn cout<<"YES\n";
#define NOn cout<<"NO\n";
#define yesn cout<<"yes\n";
#define non cout<<"no\n";
#define Nurmyrza_Quket ios_base::sync_with_stdio(0); cin.tie(NULL);
#define T ll t; cin>>t; while(t--)
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define afor(a) for(ll i=0;i<a;i++)
#define a1for(a) for(ll i=1;i<=a;i++)
#define vsort(a) sort(a.begin,a.end);
#define asort(a,n) sort(a,a+n);
#define vsortg(a) sort(a.rbegin,a.rend);
#define asortg(a,n) sort(a,a+n,greater<ll>());
#define all(a) a.begin,a.end
#define r1for(i,a,b)for(ll i=a;i<=b;i++)
#define rfor(i,a,b)for(ll i=a;i<b;i++)
#define chd2(n) __builtin_popcount(n)==1;
#define ff first
#define ss second
#define ii pair<ll,ll>
#define in insert
#define mp make_pair
//#define ll int
#define ld double
const ll LLmn=LLONG_MIN;
const ll LLmx=LLONG_MAX;
const ll MOD=1e9+7;
const ll N=1e6+7;
const ld PI=acos(-1.0);
const ll K=25;
pair <ll,ll> w[9]={mp(-1,0),mp(0,-1),mp(1,0),mp(0,1),mp(-1,-1),mp(0,1),mp(1,-1),mp(1,1)};
//(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
bool cvow(char c)
{
if(c!='a' && c!='e' && c!='i' && c!='o' && c!='u' && c!='y')return 1;
else return 0;
}
void solve()
{
ll n;cin>>n;
ll pick=0;
vector<ld>v1,v2;
afor(n)
{
ld a,b;cin>>a>>b;
v1.pb(a);
v2.pb(b);
}
vsortg(v1);
vsortg(v2);
ld o1=0.0,o2=0.0;
ld ans=0.0;
ll p1=0,p2=0;
while(true)
{
if(p1>=v1.sz && p2>=v2.sz)break;
if(p1>=v1.sz)
{
o2+=v2[p2];
p2++;
pick++;
ans=max(ans,min(o1-pick,o2-pick));
continue;
}
if(p2>=v2.sz)
{
o1+=v1[p1];
p1++;
pick++;
ans=max(ans,min(o1-pick,o2-pick));
continue;
}
if(o1==o2)
{
if(v1[p1]<=v2[p2])
{
o1+=v1[p1];
p1++;
pick++;
}
else
{
o2+=v2[p2];
p2++;
pick++;
}
}
else if(o1<=o2)
{
o1+=v1[p1];
p1++;
pick++;
}
else
{
o2+=v2[p2];
p2++;
pick++;
}
ans=max(ans,min(o1-pick,o2-pick));
}
printf("%.4lf",(double)ans);
}
int main()
{
#define JOJ
#ifdef JOJo
freopen("lca_rmq.in", "r", stdin);
freopen("lca_rmq.out", "w", stdout);
#endif
Nurmyrza_Quket;
ll cnt=1;
solve();
return 0;
}
Compilation message
sure.cpp: In function 'void solve()':
sure.cpp:110:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | if(p1>=v1.sz && p2>=v2.sz)break;
| ^
sure.cpp:110:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | if(p1>=v1.sz && p2>=v2.sz)break;
| ^
sure.cpp:111:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | if(p1>=v1.sz)
| ^
sure.cpp:119:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
119 | if(p2>=v2.sz)
| ^
sure.cpp: In function 'int main()':
sure.cpp:171:8: warning: unused variable 'cnt' [-Wunused-variable]
171 | ll cnt=1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
71 ms |
3440 KB |
Output is correct |
18 |
Correct |
73 ms |
3388 KB |
Output is correct |
19 |
Correct |
79 ms |
3424 KB |
Output is correct |
20 |
Correct |
71 ms |
3376 KB |
Output is correct |
21 |
Correct |
80 ms |
3896 KB |
Output is correct |
22 |
Correct |
73 ms |
3360 KB |
Output is correct |
23 |
Correct |
72 ms |
3400 KB |
Output is correct |
24 |
Correct |
71 ms |
3384 KB |
Output is correct |
25 |
Correct |
83 ms |
3420 KB |
Output is correct |
26 |
Correct |
77 ms |
3768 KB |
Output is correct |