Submission #725296

# Submission time Handle Problem Language Result Execution time Memory
725296 2023-04-17T08:03:48 Z fdnfksd Schools (IZhO13_school) C++14
100 / 100
136 ms 19344 KB
#include <bits/stdc++.h>
#define pb push_back
#define vii vector<int>
#define pll pair<ll, ll>
#define pii pair< ll, pair< ll, ll > >
#define fi first
#define se second
#define int ll
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const ll mod = 1e18+7;
using namespace std;
const ll N = 4e5;
ll tong, m, n, k, ans=mod, p, t, b[N], c[N], a[N], rb[N], ra[N], lab[N];
pll d[N*3];
//bool check;
string s;
vector<ll> kq, pre;
priority_queue< ll > pb, pa;

void sol()
{
    cin >> k >> n >> m;
    p=k-n-m;
    for(int i = 1 ; i <= k ;i ++)
    {

        cin >> a[i] >> b[i] ;
        a[i]*=-1;
        b[i]*=-1;
        c[i]=0;
        d[i].se = i;
        d[i].fi = a[i] - b[i];
        tong += c[i];
    }
    sort(d+1, d+1+k,greater<pair<int,int>>());
    for(int i = 1; i <= k; i ++)
    {
        pb.push(b[d[i].se] - c[d[i].se]);
        rb[i] = rb[i-1] + b[d[i].se] - c[d[i].se];
        while(pb.size() > m)
        {
            rb[i] -= pb.top();
            pb.pop();
        }
    }
    for(int i = k; i > 0; i --)
    {
        pa.push(a[d[i].se] - c[d[i].se]);
        ra[i] = ra[i+1] + a[d[i].se] - c[d[i].se];
        while(pa.size() > n)
        {
            ra[i] -= pa.top();
            pa.pop();
        }
    }
    for(int i = m; i <= k - n; i ++)
    {
        ans = min(ans, tong + ra[i+1] + rb[i]);
    }
    cout << -ans;
}

signed main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest;
    ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}

Compilation message

school.cpp: In function 'void sol()':
school.cpp:42:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   42 |         while(pb.size() > m)
      |                         ^
school.cpp:52:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   52 |         while(pa.size() > n)
      |               ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 11 ms 2728 KB Output is correct
14 Correct 30 ms 4984 KB Output is correct
15 Correct 53 ms 9096 KB Output is correct
16 Correct 66 ms 11836 KB Output is correct
17 Correct 92 ms 13916 KB Output is correct
18 Correct 105 ms 15256 KB Output is correct
19 Correct 110 ms 16620 KB Output is correct
20 Correct 136 ms 19344 KB Output is correct