CSES - Aalto Competitive Programming 2024 - wk2 - Mon - Results
Submission details
Task:Establish equality
Sender:Niilo
Submission time:2024-09-09 17:09:12 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:25:22: error: 'a' was not declared in this scope
   25 |                 s += a;
      |                      ^

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int A[200'001], n;

bool f(int s) {
	ll a = 0;
	ll b = 0;
	int i = 0;
	while (i < n && A[i] < s) {
		a += s - A[i];
	}
	while (i < n) {
		b += (A[i] - s) / 2;
	}
	return b >= a;
}

int main() {
	ll s = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
		s += a;
	}
	sort(A,A+n);
	ll a = 0;
	for (int s = 1<<31; s >= 1; s /= 2) {
		if (f(a+s)) a += s;
	}
	cout << a;
}