Submission #313923

# Submission time Handle Problem Language Result Execution time Memory
313923 2020-10-17T10:10:44 Z phathnv Kisik (COCI19_kisik) C++11
90 / 90
342 ms 25068 KB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "KISIK"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int N = 1e6 + 1;
const ll INF = 1e18;

int n, k;
ii a[N];

void readInput(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i].Y >> a[i].X;
}

void solve(){
    sort(a + 1, a + 1 + n);
    ll sumW = 0, res = INF;
    priority_queue <int> pq;
    for(int i = 1; i <= n; i++){
        pq.push(a[i].Y);
        sumW += a[i].Y;

        if (i >= k){
            res = min(res, sumW * a[i].X);
            sumW -= pq.top();
            pq.pop();
        }
    }
    cout << res;
}

int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    readInput();
    solve();
    return 0;
}

Compilation message

kisik.cpp: In function 'int main()':
kisik.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   45 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
kisik.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   46 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 404 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 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 99 ms 6584 KB Output is correct
2 Correct 238 ms 15856 KB Output is correct
3 Correct 194 ms 17388 KB Output is correct
4 Correct 176 ms 16332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 10572 KB Output is correct
2 Correct 24 ms 2688 KB Output is correct
3 Correct 48 ms 4860 KB Output is correct
4 Correct 154 ms 12912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 6772 KB Output is correct
2 Correct 202 ms 12004 KB Output is correct
3 Correct 144 ms 9080 KB Output is correct
4 Correct 329 ms 25068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 8180 KB Output is correct
2 Correct 342 ms 21520 KB Output is correct
3 Correct 96 ms 7284 KB Output is correct
4 Correct 214 ms 19052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 15060 KB Output is correct
2 Correct 231 ms 15472 KB Output is correct
3 Correct 187 ms 12684 KB Output is correct
4 Correct 105 ms 9456 KB Output is correct