Submission #73798

# Submission time Handle Problem Language Result Execution time Memory
73798 2018-08-29T04:12:33 Z 아인따(#2278) Schools (IZhO13_school) C++11
100 / 100
666 ms 17160 KB
#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

school.cpp: In function 'int main()':
school.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n,&X,&Y);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
school.cpp:32:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 1; i <= n; i++)scanf("%d%d", &A[i], &B[i]);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
6 Correct 2 ms 496 KB Output is correct
7 Correct 9 ms 540 KB Output is correct
8 Correct 11 ms 540 KB Output is correct
9 Correct 10 ms 540 KB Output is correct
10 Correct 10 ms 540 KB Output is correct
11 Correct 11 ms 540 KB Output is correct
12 Correct 11 ms 540 KB Output is correct
13 Correct 76 ms 1072 KB Output is correct
14 Correct 189 ms 1840 KB Output is correct
15 Correct 414 ms 3024 KB Output is correct
16 Correct 444 ms 3380 KB Output is correct
17 Correct 452 ms 6524 KB Output is correct
18 Correct 539 ms 9780 KB Output is correct
19 Correct 530 ms 13112 KB Output is correct
20 Correct 666 ms 17160 KB Output is correct