Submission #258020

# Submission time Handle Problem Language Result Execution time Memory
258020 2020-08-05T08:25:11 Z Vladikus004 Kisik (COCI19_kisik) C++14
90 / 90
1488 ms 67924 KB
#include <bits/stdc++.h>
#define inf 2e9
#define ff first
#define ss second
#define int long long
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int N = 1000000 + 3;
int n, k, cur;
pii a[N];
vector <int> mxs;
multiset <int> ms;

bool cmp(pii a, pii b){
    return a.ss < b.ss;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> a[i].ff >> a[i].ss;
        mxs.push_back(a[i].ss);
    }
    sort(a, a + n, cmp);
    sort(all(mxs));
    mxs.resize(unique(all(mxs)) - mxs.begin());
    int j = 0;
    ll ans = inf * 1LL * inf;
    for (int i = 0; i < mxs.size(); i++){
        while (j < n && a[j].ss <= mxs[i]){
            if (ms.size() < k) {
                ms.insert(a[j].ff);
                cur += a[j].ff;
            }else
            if (*ms.rbegin() > a[j].ff){
                cur -= *ms.rbegin();
                ms.erase(ms.lower_bound(*ms.rbegin()));
                cur += a[j].ff;
                ms.insert(a[j].ff);
            }
            j++;
        }
        if (ms.size() == k){
            ans = min(ans, cur * 1LL * mxs[i]);
        }
    }
    cout << ans;
}

Compilation message

kisik.cpp: In function 'int32_t main()':
kisik.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < mxs.size(); i++){
                     ~~^~~~~~~~~~~~
kisik.cpp:41:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (ms.size() < k) {
                 ~~~~~~~~~~^~~
kisik.cpp:53:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (ms.size() == k){
             ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 190 ms 8680 KB Output is correct
2 Correct 697 ms 29780 KB Output is correct
3 Correct 793 ms 42452 KB Output is correct
4 Correct 807 ms 39124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 348 ms 16608 KB Output is correct
2 Correct 64 ms 5744 KB Output is correct
3 Correct 130 ms 10856 KB Output is correct
4 Correct 583 ms 34272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 15592 KB Output is correct
2 Correct 280 ms 16864 KB Output is correct
3 Correct 256 ms 12768 KB Output is correct
4 Correct 1488 ms 67924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 283 ms 15712 KB Output is correct
2 Correct 1313 ms 44372 KB Output is correct
3 Correct 295 ms 15712 KB Output is correct
4 Correct 1004 ms 47956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 520 ms 21204 KB Output is correct
2 Correct 758 ms 37076 KB Output is correct
3 Correct 630 ms 26336 KB Output is correct
4 Correct 436 ms 22624 KB Output is correct