답안 #1092110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092110 2024-09-23T08:09:40 Z juicy 학교 설립 (IZhO13_school) C++17
100 / 100
74 ms 6048 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  int n, m, s; cin >> n >> m >> s;
  vector<array<int, 2>> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i][0] >> a[i][1];
  }
  sort(a.begin(), a.end(), [&](const auto &u, const auto &v) {
    return u[0] - u[1] > v[0] - v[1];
  });
  vector<long long> p(n);
  priority_queue<int> pq;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += a[i][0];
    pq.push(-a[i][0]);
    while (pq.size() > m) {
      sum += pq.top();
      pq.pop();
    }
    p[i] = sum;
  }
  sum = 0;
  priority_queue<int>().swap(pq);
  long long res = 0;
  for (int i = n; ~i; --i) {
    if (i < n) {
      sum += a[i][1];
      pq.push(-a[i][1]);
      while (pq.size() > s) {
        sum += pq.top();
        pq.pop();
      }
    }
    if (pq.size() == s && i >= m) {
      res = max(res, sum + (i ? p[i - 1] : 0));
    }
  }
  cout << res;
  return 0;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:28:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |     while (pq.size() > m) {
      |            ~~~~~~~~~~^~~
school.cpp:41:24: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |       while (pq.size() > s) {
      |              ~~~~~~~~~~^~~
school.cpp:46:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |     if (pq.size() == s && i >= m) {
      |         ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 8 ms 1120 KB Output is correct
14 Correct 19 ms 1844 KB Output is correct
15 Correct 35 ms 2984 KB Output is correct
16 Correct 42 ms 4204 KB Output is correct
17 Correct 66 ms 4768 KB Output is correct
18 Correct 61 ms 4964 KB Output is correct
19 Correct 66 ms 5228 KB Output is correct
20 Correct 74 ms 6048 KB Output is correct