Submission #339478

# Submission time Handle Problem Language Result Execution time Memory
339478 2020-12-25T11:52:49 Z beksultan04 Schools (IZhO13_school) C++14
100 / 100
155 ms 11592 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 = 3e5+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 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 3 ms 620 KB Output is correct
10 Correct 3 ms 620 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 2016 KB Output is correct
14 Correct 38 ms 3164 KB Output is correct
15 Correct 73 ms 5488 KB Output is correct
16 Correct 90 ms 9172 KB Output is correct
17 Correct 112 ms 9016 KB Output is correct
18 Correct 126 ms 9724 KB Output is correct
19 Correct 133 ms 10324 KB Output is correct
20 Correct 155 ms 11592 KB Output is correct