Submission #222115

# Submission time Handle Problem Language Result Execution time Memory
222115 2020-04-12T06:57:37 Z Vimmer Kisik (COCI19_kisik) C++14
0 / 90
862 ms 29944 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100005
#define MOD ll(998244353)

using namespace std;

typedef long long ll;

typedef long double ld;


int main()
{

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, k;

    cin >> n >> k;

    pair <ll, ll> a[n];

    for (int i = 0; i < n; i++) cin >> a[i].S >> a[i].F;

    sort(a, a + n);

    ll sum = 0, mx = 0;

    for (int i = 0; i < n; i++) swap(a[i].F, a[i].S);

    set <pair <ll, int> > se, ser; se.clear(); ser.clear();

    for (int i = 0; i < k; i++) {sum += a[i].F; mx = max(mx, a[i].S); se.insert({a[i].F, i}); ser.insert({a[i].S, i});}

    for (int i = k; i < n; i++)
    {
        pair <ll, int> nm = *se.rbegin();

        se.erase(nm);

        ser.erase({a[nm.S].S, nm.S});

        ll len = sum + a[i].F - a[nm.S].F;

        ll hg = a[i].S;

        if (sz(ser) != 0) hg = max(hg, (*ser.rbegin()).F);

        if (sum * mx >= hg * len) {sum = len; mx = hg; se.insert({a[i].F, i}); ser.insert({a[i].S, i}); continue;} else {se.insert(nm); ser.insert({a[nm.S].S, nm.S});}

        nm = *ser.rbegin();

        ser.erase(nm);

        se.erase({a[nm.S].F, nm.S});

        len = sum + a[i].F - a[nm.S].F;

        hg = a[i].S;

        if (sz(ser) != 0) hg = max(hg, (*ser.rbegin()).F);

        if (sum * mx >= hg * len) {sum = len; mx = hg; se.insert({a[i].F, i}); ser.insert({a[i].S, i});} else {ser.insert(nm); se.insert({a[nm.S].F, nm.S});}
    }

    cout << sum * mx << endl;
}
# 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 Incorrect 5 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 256 ms 5388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 563 ms 24288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 349 ms 29944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 432 ms 27136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 862 ms 25464 KB Output isn't correct
2 Halted 0 ms 0 KB -