Submission #339478

#TimeUsernameProblemLanguageResultExecution timeMemory
339478beksultan04Schools (IZhO13_school)C++14
100 / 100
155 ms11592 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...