Submission #654732

# Submission time Handle Problem Language Result Execution time Memory
654732 2022-11-01T11:57:05 Z pauloamed Sure Bet (CEOI17_sure) C++14
100 / 100
94 ms 6040 KB
#include<bits/stdc++.h>
using namespace std;

#define ld double

vector<ld> sa, sb;

ld ternary_search(int lo, int hi, ld a, int b) {
  auto f = [&](int j){
    return min(sb[j], a) - (b + j + 1);
  };

  while (hi - lo > 1){
    int mid = (hi + lo)>>1;
    if (f(mid) > f(mid + 1)) 
      hi = mid;
    else 
      lo = mid; 
  }
  return f(lo + 1);
}

int32_t main(){
  cin.tie(NULL)->sync_with_stdio(false);
  int n; cin >> n;
  vector<ld> a, b;
  for(int i = 0; i < n; ++i){
    ld x, y; cin >> x >> y;
    a.push_back(x);
    b.push_back(y);
  }

  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());

  
  for(int i = 0; i < n; ++i){
    sa.push_back(a[i]);
    sb.push_back(b[i]);
    if(i){
      sa[i] += sa[i - 1];
      sb[i] += sb[i - 1];
    }
  }

  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      ld x = min(sa[i], sb[j]);
      int y = i + j + 2;
    }
  }

  ld ans = 0;
  for(int i = 0; i < n; ++i){
    ans = max(ans, ternary_search(-1, n, sa[i], (i + 1)));
  }
  cout << setprecision(4) << fixed << ans << "\n";
}

Compilation message

sure.cpp: In function 'int32_t main()':
sure.cpp:48:10: warning: unused variable 'x' [-Wunused-variable]
   48 |       ld x = min(sa[i], sb[j]);
      |          ^
sure.cpp:49:11: warning: unused variable 'y' [-Wunused-variable]
   49 |       int y = i + j + 2;
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 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 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 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 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 86 ms 5644 KB Output is correct
18 Correct 85 ms 5556 KB Output is correct
19 Correct 87 ms 5676 KB Output is correct
20 Correct 83 ms 5584 KB Output is correct
21 Correct 94 ms 5920 KB Output is correct
22 Correct 83 ms 5580 KB Output is correct
23 Correct 85 ms 5604 KB Output is correct
24 Correct 86 ms 5644 KB Output is correct
25 Correct 84 ms 5544 KB Output is correct
26 Correct 92 ms 6040 KB Output is correct