Submission #855985

#TimeUsernameProblemLanguageResultExecution timeMemory
855985CyanmondSure Bet (CEOI17_sure)C++17
60 / 100
38 ms2804 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for (int i = (l); i < (r); ++i) #define per(i, l, r) for (int i = (r - 1); i >= l; --i) #define ALL(x) (x).begin(), (x).end() using i64 = long long; i64 parse() { i64 ret = 0; string s; cin >> s; if (find(ALL(s), '.') == s.end()) s.push_back('.'); while (s.end() - find(ALL(s), '.') <= 4) s += '0'; for (const auto e : s) { if (std::isdigit(e)) { ret = 10 * ret + (e - '0'); } else { continue; } } return ret; } void out(i64 v) { cout << v / 10000 << '.'; i64 m = v % 10000; string s = to_string(m); while (s.size() < 4) s += '0'; cout << s; cout << endl; } void main_() { int N; cin >> N; vector<i64> A(N), B(N); rep(i, 0, N) { A[i] = parse(); B[i] = parse(); } sort(ALL(A), greater()); sort(ALL(B), greater()); vector<i64> C(N + 1); rep(i, 0, N) C[i + 1] = C[i] + B[i]; i64 sum = 0; constexpr i64 X = 10000; i64 ans = 0; rep(i, 0, N + 1) { auto eval = [&](int j) { i64 a = sum - (i + j) * X; i64 b = C[j] - (i + j) * X; return min(a, b); }; int ok = -1, ng = N; while (ng - ok > 1) { const auto m = (ok + ng) / 2; i64 x = eval(m), y = eval(m + 1); if (x < y) ok = m; else ng = m; } ans = max(ans, eval(ok + 1)); if (i == N) break; sum += A[i]; } out(ans); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); main_(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...