Submission #73799

# Submission time Handle Problem Language Result Execution time Memory
73799 2018-08-29T04:13:42 Z ainta Schools (IZhO13_school) C++17
100 / 100
613 ms 5372 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 392 KB Output is correct
3 Correct 2 ms 516 KB Output is correct
4 Correct 3 ms 532 KB Output is correct
5 Correct 3 ms 608 KB Output is correct
6 Correct 2 ms 608 KB Output is correct
7 Correct 10 ms 620 KB Output is correct
8 Correct 10 ms 672 KB Output is correct
9 Correct 11 ms 672 KB Output is correct
10 Correct 12 ms 672 KB Output is correct
11 Correct 11 ms 672 KB Output is correct
12 Correct 12 ms 672 KB Output is correct
13 Correct 85 ms 1060 KB Output is correct
14 Correct 182 ms 1772 KB Output is correct
15 Correct 385 ms 3052 KB Output is correct
16 Correct 486 ms 3308 KB Output is correct
17 Correct 463 ms 4024 KB Output is correct
18 Correct 496 ms 4460 KB Output is correct
19 Correct 535 ms 4732 KB Output is correct
20 Correct 613 ms 5372 KB Output is correct