# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169512 | muhammad_hokimiyon | Schools (IZhO13_school) | C++14 | 262 ms | 17520 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define ll long long
using namespace std;
const int N = 3e5 + 7;
const int mod = 1e9 + 7;
ll n,m,ss;
ll pr[N];
ll sf[N];
pair < ll , pair < ll , ll > > p[N];
void solve()
{
cin >> n >> m >> ss;
for( int i = 1; i <= n; i++ ){
cin >> p[i].se.fi >> p[i].se.se;
p[i].fi = p[i].se.fi - p[i].se.se;
}
sort( p + 1 , p + n + 1 );
reverse( p + 1 , p + n + 1 );
multiset < ll > s;
for( int i = 1; i <= n; i++ ){
pr[i] = pr[i - 1] + p[i].se.fi;
s.insert(p[i].se.fi);
if( i > m ){
pr[i] -= *s.begin();
s.erase(s.begin());
}
}
s.clear();
for( int i = n; i >= 1; i-- ){
sf[i] = sf[i + 1] + p[i].se.se;
s.insert(p[i].se.se);
if( n - i + 1 > ss ){
sf[i] -= *s.begin();
s.erase(s.begin());
}
}
ll ans = 0;
for( int i = m; i <= n - ss; i++ ){
ans = max( ans , pr[i] + sf[i + 1] );
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int t = 1;//cin >> t;
while( t-- ){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |