# Codeforces Round #491 (Div. 2)题解

## A. If at first you don’t succeed…

#include <bits/stdc++.h>
using namespace std;
int main()
{
// freopen("in.txt", "r", stdin);
int a, b, c, n;
cin >> a >> b >> c >> n;
int ans1 = a - c;
int ans2 = b - c;
if (ans1 < 0 || ans2 < 0)
{
cout << -1 << endl;
return 0;
}
int ans = n - ans1 - ans2 - c;
if (ans > 0)
cout << ans << endl;
else
cout << -1 << endl;

return 0;
}

## B. Getting an A

#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
double a[N];
int n;
int judge()
{
double sum = 0;
for (int i = 0; i < n; i++)
{
sum += a[i];
}
int ans = (int)(sum / (n * 1.0) + 0.5);
return ans >= 5;
}
int main()
{

scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%lf", &a[i]);
}
sort(a, a + n);
if (judge())
{
printf("0\n");
}
else
{
int cnt = 0;
for (int i = 0; i < n; i++)
{
a[i] = 5.0;
cnt++;
if (judge())
{
printf("%d\n", cnt);
break;
}
}
}

return 0;
}

## C. Candies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll judge(ll m)
{
ll nn = n, cnt = 0;
while (nn > 0)
{
cnt += min(nn, m);
nn -= m;
nn -= nn / 10;
}
return cnt >= (n + 1) / 2;
}
int main()
{
scanf("%lld", &n);
ll l = 1, r = n;
while (l < r)
{
ll mid = (l + r) / 2;
if (judge(mid))
r = mid;
else
l = mid + 1;
}
printf("%lld\n", l);
return 0;
}