# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30843 | 2017-07-27T15:51:18 Z | Kerim | Schools (IZhO13_school) | C++14 | 0 ms | 6712 KB |
#include "bits/stdc++.h" #define MAXN 300009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} PII arr[MAXN]; ll suf[MAXN]; multiset<int>st; bool cmp(PII x,PII y){ return (x.ss-x.ff<y.ss-y.ff); } int main(){ //~ #ifndef ONLINE_JUDGE //~ freopen("file.in", "r", stdin); //~ #endif int n,a,b; scanf("%d%d%d",&n,&a,&b); for(int i=1;i<=n;i++) scanf("%d%d",&arr[i].ff,&arr[i].ss); sort(arr+1,arr+n+1,cmp); ll ans=0,cur=0; for(int i=n;i>n-b;i--) st.insert(arr[i].ss),cur+=arr[i].ss; for(int i=n-b+1;i>a;i--){ if(*st.begin()<arr[i].ff){ cur-=*st.begin();cur+=arr[i].ss; st.erase(st.begin()); st.insert(arr[i].ss); }suf[i]=cur; }st.clear();cur=0; for(int i=1;i<=a;i++) st.insert(arr[i].ff),cur+=arr[i].ff; for(int i=a;i<=n-b;i++){ if(*st.begin()<arr[i].ff){ cur-=*st.begin();cur+=arr[i].ff; st.erase(st.begin()); st.insert(arr[i].ff); } umax(ans,cur+suf[i+1]); } printf("%lld\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6712 KB | Output is correct |
2 | Incorrect | 0 ms | 6712 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |