| Task: | Establish equality |
| Sender: | aalto26bm_026 |
| Submission time: | 2026-09-07 17:50:28 +0300 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:46:18: error: redeclaration of 'uint64_t k'
46 | uint64_t k = a + (b - a) / 2;
| ^
input/code.cpp:40:18: note: 'uint64_t k' previously declared here
40 | uint64_t k = a + (b - a) / 2;
| ^Code
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdint.h>
using namespace std;
bool isValidSolution(const vector<uint64_t>& bottles, uint64_t target)
{
uint64_t deficit, surplus;
deficit = surplus = 0;
for (size_t i = 0; i < bottles.size(); i++)
{
if (bottles[i] < target)
{
deficit += target - bottles[i];
}
else
{
surplus += bottles[i] - target;
}
}
return surplus >= 2 * deficit;
}
int main()
{
uint64_t n;
cin >> n;
vector<uint64_t> bottles(n);
for (size_t i = 0; i < n; i++)
{
cin >> bottles[i];
}
uint64_t bestSolution = 0;
uint64_t a = 0, b = 1000000000;
while (a <= b)
{
uint64_t k = a + (b - a) / 2;
if (a == b)
{
k = a;
}
uint64_t k = a + (b - a) / 2;
if (isValidSolution(bottles, k))
{
bestSolution = k;
a = k + 1;
}
else
{
b = k - 1;
}
}
cout << bestSolution << endl;
}