Submission #73799

#TimeUsernameProblemLanguageResultExecution timeMemory
73799aintaSchools (IZhO13_school)C++17
100 / 100
613 ms5372 KiB
#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)

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 timeMemoryGrader output
Fetching results...