Submission #169575

# Submission time Handle Problem Language Result Execution time Memory
169575 2019-12-21T07:43:59 Z davitmarg Schools (IZhO13_school) C++17
30 / 100
221 ms 19696 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 300005;

int n, m, s, k;
LL ans = 0;
pair<LL, LL> a[N];
multiset<pair<LL, LL>> M, S;
vector<pair<LL, LL>> K;
int main()
{
    cin >> n >> m >> s;
    k = n - m - s;
    for (int i = 1; i <= n; i++)
        scanf("%lld%lld", &a[i].first, &a[i].second);
    sort(a + 1, a + 1 + n, [](pair<LL, LL> a, pair<LL, LL> b) {
        return a.first - a.second < b.first - b.second;
    });
    for (int i = 1; i <= s; i++)
    {
        ans += a[i].second;
        swap(a[i].first, a[i].second);
        S.insert(a[i]);
    }
    for (int i = s + 1; i <= s + k; i++)
        K.PB(a[i]);

    for (int i = s + k + 1; i <= n; i++)
    {
        ans += a[i].first;
        M.insert(a[i]);
    }

    sort(all(K));

    while (!K.empty())
    {
        LL x = K.back().first, y = K.back().second;
        K.pop_back();
        LL d1 = -1, d2 = -1;
        if (!M.empty())
            d1 = x - (*M.begin()).first;
        if (!S.empty())
            d2 = y - (*S.begin()).first;
        if (max(d1, d2) <= 0)
            continue;
        pair<LL, LL> p;
        if (d1 >= d2)
        {
            p = *M.begin();
            M.erase(M.begin());
            //M.insert(x);
            ans += d1;
        }
        else
        {
            p = *S.begin();
            swap(p.first, p.second);
            S.erase(S.begin());
            //S.insert(y);
            ans += d2;
        }
        K.PB(p);
    }
    cout << ans << endl;
    return 0;
}

/*


2
BB
1000 1003
1000 1000


*/

Compilation message

school.cpp: In function 'int main()':
school.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &a[i].first, &a[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 0 ms 376 KB Output is correct
5 Incorrect 2 ms 248 KB Output isn't correct
6 Incorrect 3 ms 376 KB Output isn't correct
7 Incorrect 4 ms 504 KB Output isn't correct
8 Correct 4 ms 760 KB Output is correct
9 Incorrect 4 ms 632 KB Output isn't correct
10 Incorrect 5 ms 760 KB Output isn't correct
11 Incorrect 4 ms 632 KB Output isn't correct
12 Incorrect 5 ms 696 KB Output isn't correct
13 Incorrect 26 ms 2992 KB Output isn't correct
14 Incorrect 44 ms 4204 KB Output isn't correct
15 Incorrect 79 ms 7524 KB Output isn't correct
16 Correct 167 ms 14328 KB Output is correct
17 Incorrect 173 ms 16108 KB Output isn't correct
18 Incorrect 176 ms 16004 KB Output isn't correct
19 Incorrect 194 ms 17720 KB Output isn't correct
20 Incorrect 221 ms 19696 KB Output isn't correct