Submission #222107

# Submission time Handle Problem Language Result Execution time Memory
222107 2020-04-12T06:43:07 Z kartel Kisik (COCI19_kisik) C++14
90 / 90
1268 ms 75712 KB
#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
#define M ll(998244353)
#define inf ll(2e9+7)
#define N ll(200500)
#define sz(x) x.size()
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define el '\n'
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> os;

multiset <pair <ll, ll> , greater <pair <ll, ll> > > se;
ll w, h, i, n, k, ans;
vector <pair <ll, ll> > v;

int main()
{
//    in("input.txt");
//    out("output.txt");

    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;

    for (i = 1; i <= n; i++)
    {
        cin >> w >> h;
        v.pb({w, h});
    }

    w = 0;

    sort(v.begin(), v.end());

    for (i = 0; i < k; i++) se.insert({v[i].S, v[i].F}), w += v[i].F, h = (*se.begin()).F;

    ans = w * h;

    for (i = k; i < n; i++)
    {
        if (v[i].S < (*se.begin()).F)
        {
            w -= (*se.begin()).S;
            se.erase(se.begin());
            w += v[i].F;
            se.insert({v[i].S, v[i].F});
            h = (*se.begin()).F;
            ans = min(ans, w * h);
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 416 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 8808 KB Output is correct
2 Correct 601 ms 30016 KB Output is correct
3 Correct 709 ms 47296 KB Output is correct
4 Correct 659 ms 43968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 348 ms 15576 KB Output is correct
2 Correct 54 ms 6832 KB Output is correct
3 Correct 133 ms 12512 KB Output is correct
4 Correct 586 ms 38620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 220 ms 16992 KB Output is correct
2 Correct 199 ms 17364 KB Output is correct
3 Correct 219 ms 11480 KB Output is correct
4 Correct 1268 ms 75712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 261 ms 16084 KB Output is correct
2 Correct 985 ms 45588 KB Output is correct
3 Correct 246 ms 17108 KB Output is correct
4 Correct 841 ms 53956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 384 ms 17988 KB Output is correct
2 Correct 700 ms 40420 KB Output is correct
3 Correct 510 ms 28112 KB Output is correct
4 Correct 320 ms 25684 KB Output is correct