Submission #679821

#TimeUsernameProblemLanguageResultExecution timeMemory
679821peijarSure Bet (CEOI17_sure)C++17
60 / 100
2062 ms6324 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
  out << "[";
  for (int i = 0; i < (int)vec.size(); ++i) {
    out << vec[i];
    if (i + 1 < (int)vec.size())
      out << ", ";
  }
  return out << "]";
}
} // namespace std

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cout << ' ' << H;
  dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  vector<double> a(n), b(n);

  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  vector<double> valA(a.begin(), a.end());
  vector<double> valB(b.begin(), b.end());
  valA.resize(unique(valA.begin(), valA.end()) - valA.begin());
  valB.resize(unique(valB.begin(), valB.end()) - valB.begin());
  int cntA = valA.size();
  int cntB = valB.size();
  vector<double> suffA(n + 1), suffB(n + 1);
  for (int i = n - 1; i >= 0; --i) {
    suffA[i] = suffA[i + 1] + a[i];
    suffB[i] = suffB[i + 1] + b[i];
  }
  double sol = 0;

  for (int takeA = 0; takeA <= cntA; ++takeA) {
    for (int takeB = 0; takeB <= cntB; ++takeB) {
      double fromA = takeA == 0 ? 1e9 : valA[cntA - takeA];
      double fromB = takeB == 0 ? 1e9 : valB[cntB - takeB];

      int loA = lower_bound(a.begin(), a.end(), fromA) - a.begin();
      int loB = lower_bound(b.begin(), b.end(), fromB) - b.begin();
      double cost = 2 * n - loA - loB;
      sol = max(sol, min(suffA[loA] - cost, suffB[loB] - cost));
    }
  }
  printf("%.4lf", sol);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...