제출 #1092110

#제출 시각아이디문제언어결과실행 시간메모리
1092110juicy학교 설립 (IZhO13_school)C++17
100 / 100
74 ms6048 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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) {
      |         ~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...