답안 #564068

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564068 2022-05-18T14:00:43 Z hoanghq2004 Sure Bet (CEOI17_sure) C++14
100 / 100
85 ms 3660 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(4) << 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 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 83 ms 3136 KB Output is correct
18 Correct 79 ms 3112 KB Output is correct
19 Correct 77 ms 3136 KB Output is correct
20 Correct 72 ms 3220 KB Output is correct
21 Correct 78 ms 3536 KB Output is correct
22 Correct 71 ms 3140 KB Output is correct
23 Correct 69 ms 3140 KB Output is correct
24 Correct 73 ms 3152 KB Output is correct
25 Correct 72 ms 3240 KB Output is correct
26 Correct 85 ms 3660 KB Output is correct