답안 #1027244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027244 2024-07-19T02:40:26 Z vjudge1 Sure Bet (CEOI17_sure) C++17
100 / 100
99 ms 6604 KB
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define pll2 pair<pll,ll>
#define bit(i,k) ((k>>i)&1)
#define pii pair<int,int>
using namespace std;
const long long mod = 998244353;
const ll inf = 1e18;
const ll maxN=1e5+5;


ld a[maxN],b[maxN];
bool cmp(ld a,ld b){
  return a>b;
}
ld pfs1[maxN],pfs2[maxN];
void solve(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i]>>b[i];
  }
  sort(a+1,a+n+1,cmp);
  sort(b+1,b+n+1,cmp);
  for(int i=1;i<=n;i++){
    pfs1[i]=pfs1[i-1]+a[i];
    pfs2[i]=pfs2[i-1]+b[i];
  }
  ld ans=0;
  for(int i=0;i<=n;i++){
    ll res=0;
    ll l=0,r=n;
    ll target=n+1;
    while(l<=r){
      ll md=(l+r)/2;
      if(pfs2[md]<pfs1[i]){
        l=md+1;
        target=md;
      }
      else{
        r=md-1;
      }
    }
    if(target<=n){
         ans=max(ans,min(pfs1[i],pfs2[target])-i-target);
    }
    target++;
    if(target<=n){
         ans=max(ans,min(pfs1[i],pfs2[target])-i-target);
    }
  }
  cout<<setprecision(4)<<fixed<<ans;

}
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //  freopen("lottery.inp", "r", stdin);
    // freopen("lottery.out", "w", stdout);
    ll nhim = 1;
    // cin >> nhim;
    // cout<<nhim<<'\n';
    while (nhim--) {
        solve();
    }
}

Compilation message

sure.cpp: In function 'void solve()':
sure.cpp:42:8: warning: unused variable 'res' [-Wunused-variable]
   42 |     ll res=0;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 99 ms 6596 KB Output is correct
18 Correct 86 ms 6484 KB Output is correct
19 Correct 99 ms 6528 KB Output is correct
20 Correct 85 ms 6484 KB Output is correct
21 Correct 88 ms 6532 KB Output is correct
22 Correct 85 ms 6484 KB Output is correct
23 Correct 80 ms 6480 KB Output is correct
24 Correct 87 ms 6476 KB Output is correct
25 Correct 86 ms 6520 KB Output is correct
26 Correct 85 ms 6604 KB Output is correct