답안 #123235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123235 2019-06-30T14:12:18 Z cvele Kisik (COCI19_kisik) C++14
80 / 90
2000 ms 60348 KB
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

#define int long long

const int N = 1000005;

int n, k;
vector < pair <int, int> > vec;
multiset <int> ms;

int32_t main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int w, h;
    cin >> w >> h;
    vec.push_back({h, w});
  }
  sort(vec.begin(), vec.end());
  int pos = 0;
  long long ans = 2e18, sum = 0;
  for (int i = 1; i < N; i++) {
    while (pos < vec.size() && vec[pos].first <= i) {
      sum += vec[pos].second;
      ms.insert(vec[pos].second);
      while (ms.size() > k) {
        sum -= *ms.rbegin();
        ms.erase(--ms.end());
      }
      pos++;
    }
    if (ms.size() == k) {
      ans = min(ans, 1ll * sum * i);
    }
  }
  cout << ans << endl;
  return 0;
}

Compilation message

kisik.cpp: In function 'int32_t main()':
kisik.cpp:41:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (pos < vec.size() && vec[pos].first <= i) {
            ~~~~^~~~~~~~~~~~
kisik.cpp:44:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       while (ms.size() > k) {
              ~~~~~~~~~~^~~
kisik.cpp:50:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (ms.size() == k) {
         ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 252 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 8672 KB Output is correct
2 Correct 1157 ms 24936 KB Output is correct
3 Correct 1248 ms 37540 KB Output is correct
4 Correct 1138 ms 34892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 708 ms 13424 KB Output is correct
2 Correct 132 ms 5224 KB Output is correct
3 Correct 277 ms 9784 KB Output is correct
4 Correct 935 ms 30672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 13660 KB Output is correct
2 Correct 722 ms 16848 KB Output is correct
3 Correct 572 ms 9808 KB Output is correct
4 Execution timed out 2056 ms 60348 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 615 ms 13392 KB Output is correct
2 Correct 1740 ms 37460 KB Output is correct
3 Correct 471 ms 13640 KB Output is correct
4 Correct 1633 ms 42812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1008 ms 16992 KB Output is correct
2 Correct 1240 ms 32580 KB Output is correct
3 Correct 902 ms 22740 KB Output is correct
4 Correct 597 ms 20276 KB Output is correct