Submission #339477

# Submission time Handle Problem Language Result Execution time Memory
339477 2020-12-25T11:52:26 Z beksultan04 Schools (IZhO13_school) C++14
70 / 100
165 ms 17244 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-15
const int N = 1e5+12,INF=1e9+7;
int ans[2][N];
bool comp(pii a, pii b){
    ret (a.fr-a.sc)>(b.fr-b.sc);

}
main(){
    int n,x,y,i,j,mx=0,sum=0;
    scan3(n,x,y)
    vector <pii> v;
    for (i=0;i<n;++i){
        int a,b;
        scan2(a,b)
        v.pb({a,b});
    }
    sort(all(v),comp);
    priority_queue <int, vector<int> , greater<int>> t;
    for (i=0;i<n;++i){
        sum+=v[i].fr;
        t.push(v[i].fr);
        if (i >= x){
            sum-=t.top();
            t.pop();
        }
        ans[0][i]=sum;
    }
    sum=0;
    while (!t.empty())t.pop();


    for (i=n-1;i>=0;--i){
        sum+=v[i].sc;
        t.push(v[i].sc);
        if ((n-i) > y){
            sum-=t.top();
            t.pop();
        }
        ans[1][i]=sum;
    }



    for (i=0;i<n;++i){
        mx = max(mx,ans[0][i]+ans[1][i+1]);
    }
    cout <<mx;
}






Compilation message

school.cpp:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main(){
      |      ^
school.cpp: In function 'int main()':
school.cpp:27:17: warning: unused variable 'j' [-Wunused-variable]
   27 |     int n,x,y,i,j,mx=0,sum=0;
      |                 ^
school.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 | #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:28:5: note: in expansion of macro 'scan3'
   28 |     scan3(n,x,y)
      |     ^~~~~
school.cpp:12:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
school.cpp:32:9: note: in expansion of macro 'scan2'
   32 |         scan2(a,b)
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 20 ms 1888 KB Output is correct
14 Correct 39 ms 3164 KB Output is correct
15 Runtime error 69 ms 8364 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 86 ms 10068 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 120 ms 14420 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 133 ms 15080 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 144 ms 15700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 165 ms 17244 KB Execution killed with signal 11 (could be triggered by violating memory limits)