답안 #564066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564066 2022-05-18T14:00:05 Z hoanghq2004 Sure Bet (CEOI17_sure) C++14
0 / 100
1 ms 324 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n;
double a[N], b[N], ans = -1e9;

double calc(int i, int j) {
    return min(a[i], b[j]) - i - j;
}

void divide(int L, int R, int from, int to) {
    if (L > R) return;
    int mid = L + R >> 1;
    double cur = -1e9;
    int best = from;
    for (int i = from; i <= to; ++i) {
        if (calc(mid, i) > cur) {
            cur = calc(mid, i);
            best = i;
        }
    }
    ans = max(ans, cur);
    divide(L, mid - 1, from, best);
    divide(mid + 1, R, best, to);
}

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    reverse(b + 1, b + n + 1);
    for (int i = 1; i <= n; ++i) a[i] += a[i - 1], b[i] += b[i - 1];
    divide(0, n, 0, n);
    cout << setprecision(6) << fixed << ans;
}

Compilation message

sure.cpp: In function 'void divide(int, int, int, int)':
sure.cpp:16:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   16 |     int mid = L + R >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -