답안 #570775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570775 2022-05-31T09:19:20 Z Shin Sure Bet (CEOI17_sure) C++14
100 / 100
90 ms 3524 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(), x.end()

using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
    if (a > b) return a = b, true;
    return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
    if (a < b) return a = b, true;
    return false;
}

const int N = 1e5 + 7;

int n;
int f[N];
double a[N];
double b[N];
double pre_a[N];
double pre_b[N];
double res;

void backtrack(int i) {
  if (i > n) {
    int cur = 0;
    double l = 0, r = 0;
    for (int j = 1; j <= n; j ++) {
      if (f[j] == 1) {
        cur --;
        l += a[j];
      } else
      if (f[j] == 2) {
        cur --;
        r += b[j];
      } else
      if (f[j] != 0) {
        cur -= 2;
        l += a[j];
        r += b[j];
      }
    }
    maximize(res, min(r, l) + cur);
    return;
  }
  for (int j = 0; j < 4; j ++) {
    f[i] = j;
    backtrack(i + 1);
  }
}

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i ++) {
    cin >> a[i] >> b[i];
  } 
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  reverse(a + 1, a + n + 1);
  reverse(b + 1, b + n + 1);
  for (int i = 1; i <= n; i ++) {
    pre_a[i] = pre_a[i - 1] + a[i];
    pre_b[i] = pre_b[i - 1] + b[i];
  }
  if (n <= 10) {
    backtrack(1);
  } else {
    for (int i = 1, j = 1; i <= n; i ++) {
      while (j < n && pre_a[j + 1] <= pre_b[i]) {
        j ++;
      }
      if (pre_b[i] < pre_a[j]) {  
        maximize(res, pre_b[i] - i - j);
      } else {
        maximize(res, pre_a[j] - i - j);
        if (j < n) maximize(res, pre_b[i] - i - j - 1);
      }
    }
  }

  cout << fixed << setprecision(4) << res;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 47 ms 340 KB Output is correct
4 Correct 46 ms 340 KB Output is correct
5 Correct 46 ms 340 KB Output is correct
6 Correct 51 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 47 ms 340 KB Output is correct
4 Correct 46 ms 340 KB Output is correct
5 Correct 46 ms 340 KB Output is correct
6 Correct 51 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 47 ms 340 KB Output is correct
4 Correct 46 ms 340 KB Output is correct
5 Correct 46 ms 340 KB Output is correct
6 Correct 51 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 78 ms 3524 KB Output is correct
18 Correct 88 ms 3412 KB Output is correct
19 Correct 87 ms 3408 KB Output is correct
20 Correct 79 ms 3388 KB Output is correct
21 Correct 77 ms 3320 KB Output is correct
22 Correct 82 ms 3344 KB Output is correct
23 Correct 90 ms 3344 KB Output is correct
24 Correct 69 ms 3404 KB Output is correct
25 Correct 70 ms 3352 KB Output is correct
26 Correct 83 ms 3332 KB Output is correct