Submission #441212

# Submission time Handle Problem Language Result Execution time Memory
441212 2021-07-04T16:34:17 Z parsabahrami Schools (IZhO13_school) C++17
5 / 100
287 ms 19004 KB
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 3e5 + 10, MOD = 1e9 + 7;
int A[N], B[N], ord[N], M[N], m, s, n; set<pii, greater<pii>> st1, st2;

int main() {
    scanf("%d%d%d", &n, &m, &s);
    /* for (int i = 1; i <= n; i++) 
        scanf("%d%d", &A[i], &B[i]);*/ 
    for (int i = 1; i <= n; i++) 
        scanf("%d", &A[i]);
    for (int i = 1; i <= n; i++) 
        scanf("%d", &B[i]);
    iota(ord + 1, ord + n + 1, 1);
    sort(ord + 1, ord + n + 1, [&] (int a, int b) { return A[a] > A[b]; });
    ll sum = 0;
    for (int i = 1; i <= m; i++) {
        st1.insert({B[ord[i]] - A[ord[i]], ord[i]}); 
        M[ord[i]] = 1;
        sum += A[ord[i]];
    }
    for (int i = m + 1; i <= n; i++) 
        st2.insert({B[ord[i]], ord[i]});
    int ptr = m + 1;
    for (int i = 1; i <= s; i++) {
        while (ptr <= n && M[ord[ptr]]) ptr++;
        int c1 = (SZ(st1) ? st1.begin()->F + A[ord[ptr]] : -MOD),
            c2 = (SZ(st2) ? st2.begin()->F : -MOD);
        if (c2 > c1) {
            //printf("1 %d ", st2.begin()->S);
            M[st2.begin()->S] = 1, sum += c2;
            st2.erase(st2.begin());
        } else {
            //printf("2 %d ", st1.begin()->S);
            M[st1.begin()->S] = 1, sum += c1;
            st1.erase(st1.begin());
            st1.insert({B[ord[ptr]] - A[ord[ptr]], ord[ptr]}); M[ord[ptr]] = 1;
            st2.erase({B[ord[ptr]], ord[ptr]});
        }
        //printf("%lld\n", sum);
    }
    printf("%lld\n", sum);
    return 0;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d%d%d", &n, &m, &s);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
school.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%d", &A[i]);
      |         ~~~~~^~~~~~~~~~~~~
school.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d", &B[i]);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Incorrect 3 ms 588 KB Output isn't correct
8 Incorrect 3 ms 588 KB Output isn't correct
9 Incorrect 3 ms 588 KB Output isn't correct
10 Incorrect 3 ms 588 KB Output isn't correct
11 Incorrect 3 ms 588 KB Output isn't correct
12 Incorrect 3 ms 588 KB Output isn't correct
13 Incorrect 22 ms 2448 KB Output isn't correct
14 Incorrect 54 ms 5088 KB Output isn't correct
15 Incorrect 152 ms 10216 KB Output isn't correct
16 Incorrect 173 ms 11460 KB Output isn't correct
17 Incorrect 210 ms 13968 KB Output isn't correct
18 Incorrect 211 ms 15348 KB Output isn't correct
19 Incorrect 242 ms 16448 KB Output isn't correct
20 Incorrect 287 ms 19004 KB Output isn't correct