# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954710 | starchan | Schools (IZhO13_school) | C++17 | 113 ms | 15636 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>
using namespace std;
#define int long long
#define pq priority_queue
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
struct ritul
{
int Limit;
int sum;
pq<int> chungus;
void init(int x)
{
Limit = x;
while(!chungus.empty())
chungus.pop();
sum = 0;
return;
}
void push(int x)
{
chungus.push(-x);
sum+=x;
if(chungus.size() > Limit)
{
sum+=chungus.top();
chungus.pop();
}
return;
}
int ans()
{
return sum;
}
};
signed main()
{
fast(); ritul work;
int n, A, B; cin >> n >> A >> B;
vector<int> a(n+1), b(n+1), d(n+1, 0), e(n+1, 0); vector<in> c(n+1);
for(int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
c[i] = {b[i]-a[i], i};
}
sort(c.begin(), c.end());
work.init(A);
for(int i = 1; i <= n; i++)
{
work.push(a[c[i].s]);
d[i] = work.ans();
}
work.init(B);
for(int i = n; i >= 1; i--)
{
work.push(b[c[i].s]);
e[i] = work.ans();
}
int ans = -1;
for(int i = 0; i < n; i++)
ans = max(ans, d[i]+e[i+1]);
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |