# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
73799 | ainta | Schools (IZhO13_school) | C++17 | 613 ms | 5372 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<cstdio>
#include<algorithm>
#define BS 100000
using namespace std;
int n, A[301000], B[301000], X, Y, c;
long long sum;
struct point {
int a, ck;
bool operator < (const point &p)const {
return a != p.a ? a < p.a : ck < p.ck;
}
}w[301000];
bool Pos(int d) {
int i;
for (i = 1; i <= n; i++) {
if (A[i] <= B[i] + d) {
w[i] = { B[i]+d,1 };
}
else w[i] = { A[i],0 };
}
sort(w + 1, w + n + 1);
sum = 0, c = 0;
for (i = n; i > n - X - Y; i--) {
sum += w[i].a;
if (w[i].ck)c++;
}
return c >= Y;
}
int main() {
int b = 0, e = 2*BS, mid, r = 0, i;
scanf("%d%d%d", &n,&X,&Y);
for (i = 1; i <= n; i++)scanf("%d%d", &A[i], &B[i]);
while (b <= e) {
mid = (b + e) >> 1;
if (Pos(mid - BS)) {
r = mid - BS;
e = mid - 1;
}
else b = mid + 1;
}
Pos(r);
printf("%lld\n",sum - 1ll*Y*r);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |