답안 #1060764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1060764 2024-08-15T22:12:37 Z MilosMilutinovic Tricks of the Trade (CEOI23_trade) C++14
10 / 100
8000 ms 4512 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  const long long inf = (long long) -1e18;
  long long res = inf;
  auto Calc = [&](int l, int r) {
    if (r - l + 1 < k) {
      return inf;
    }
    vector<int> v;
    long long ret = 0;
    for (int i = l; i <= r; i++) {
      ret -= c[i];
      v.push_back(s[i]);
    }
    sort(v.rbegin(), v.rend());
    for (int i = 0; i < min(k, (int) v.size()); i++) {
      ret += v[i];
    }
    return ret;
  };
  function<void(int, int, int, int)> Solve = [&](int l, int r, int optl, int optr) {
    if (l > r) {
      return;
    }
    int mid = (l + r) >> 1;
    int opt = min(optl, mid);
    long long best = Calc(opt, mid);
    for (int i = optl; i <= min(mid, optr); i++) {
      long long v = Calc(i, mid);
      if (v > best) {
        best = v;
        opt = i;
      }
    }
    res = max(res, best);
    Solve(l, mid - 1, optl, opt);
    Solve(mid + 1, r, opt, optr);
  };
  Solve(0, n - 1, 0, n - 1);
  cout << res << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 344 KB Partially correct
2 Partially correct 0 ms 348 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Partially correct
2 Partially correct 1 ms 348 KB Partially correct
3 Partially correct 0 ms 348 KB Partially correct
4 Partially correct 2 ms 464 KB Partially correct
5 Partially correct 0 ms 348 KB Partially correct
6 Partially correct 1 ms 348 KB Partially correct
7 Partially correct 2 ms 348 KB Partially correct
8 Partially correct 1 ms 348 KB Partially correct
9 Partially correct 2 ms 348 KB Partially correct
10 Partially correct 1 ms 460 KB Partially correct
11 Partially correct 1 ms 452 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Partially correct
2 Partially correct 1 ms 348 KB Partially correct
3 Partially correct 0 ms 348 KB Partially correct
4 Partially correct 2 ms 464 KB Partially correct
5 Partially correct 0 ms 348 KB Partially correct
6 Partially correct 1 ms 348 KB Partially correct
7 Partially correct 2 ms 348 KB Partially correct
8 Partially correct 1 ms 348 KB Partially correct
9 Partially correct 2 ms 348 KB Partially correct
10 Partially correct 1 ms 460 KB Partially correct
11 Partially correct 1 ms 452 KB Partially correct
12 Partially correct 0 ms 348 KB Partially correct
13 Partially correct 0 ms 456 KB Partially correct
14 Partially correct 0 ms 348 KB Partially correct
15 Partially correct 3 ms 600 KB Partially correct
16 Partially correct 1 ms 348 KB Partially correct
17 Partially correct 1 ms 348 KB Partially correct
18 Partially correct 3 ms 348 KB Partially correct
19 Partially correct 1 ms 348 KB Partially correct
20 Partially correct 2 ms 348 KB Partially correct
21 Partially correct 2 ms 452 KB Partially correct
22 Partially correct 1 ms 456 KB Partially correct
23 Partially correct 3 ms 600 KB Partially correct
24 Partially correct 1285 ms 572 KB Partially correct
25 Partially correct 5325 ms 568 KB Partially correct
26 Partially correct 3755 ms 568 KB Partially correct
27 Partially correct 1674 ms 564 KB Partially correct
28 Partially correct 240 ms 344 KB Partially correct
29 Partially correct 2798 ms 600 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Partially correct
2 Execution timed out 8077 ms 4512 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Partially correct
2 Execution timed out 8077 ms 4512 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 344 KB Partially correct
2 Partially correct 0 ms 348 KB Partially correct
3 Partially correct 0 ms 348 KB Partially correct
4 Partially correct 1 ms 348 KB Partially correct
5 Partially correct 0 ms 348 KB Partially correct
6 Partially correct 2 ms 464 KB Partially correct
7 Partially correct 0 ms 348 KB Partially correct
8 Partially correct 1 ms 348 KB Partially correct
9 Partially correct 2 ms 348 KB Partially correct
10 Partially correct 1 ms 348 KB Partially correct
11 Partially correct 2 ms 348 KB Partially correct
12 Partially correct 1 ms 460 KB Partially correct
13 Partially correct 1 ms 452 KB Partially correct
14 Partially correct 0 ms 348 KB Partially correct
15 Partially correct 0 ms 456 KB Partially correct
16 Partially correct 0 ms 348 KB Partially correct
17 Partially correct 3 ms 600 KB Partially correct
18 Partially correct 1 ms 348 KB Partially correct
19 Partially correct 1 ms 348 KB Partially correct
20 Partially correct 3 ms 348 KB Partially correct
21 Partially correct 1 ms 348 KB Partially correct
22 Partially correct 2 ms 348 KB Partially correct
23 Partially correct 2 ms 452 KB Partially correct
24 Partially correct 1 ms 456 KB Partially correct
25 Partially correct 3 ms 600 KB Partially correct
26 Partially correct 1285 ms 572 KB Partially correct
27 Partially correct 5325 ms 568 KB Partially correct
28 Partially correct 3755 ms 568 KB Partially correct
29 Partially correct 1674 ms 564 KB Partially correct
30 Partially correct 240 ms 344 KB Partially correct
31 Partially correct 2798 ms 600 KB Partially correct
32 Partially correct 0 ms 348 KB Partially correct
33 Execution timed out 8077 ms 4512 KB Time limit exceeded
34 Halted 0 ms 0 KB -