output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X sqr(const X& a) {
return a * a;
}
int nxt() {
int x;
cin >> x;
return x;
}
int main() {
int n = nxt();
long long s;
cin >> s;
vector<int> a(n);
generate(a.begin(), a.end(), nxt);
if (accumulate(a.begin(), a.end(), 0ll) < s) {
cout << -1 << '\n';
return 0;
}
int mn = *min_element(a.begin(), a.end());
for (int i = 0; i < int(n); ++i) {
s -= a[i] - mn;
}
s = max(s, 0ll);
cout << mn - (s + n - 1) / n << '\n';
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X sqr(const X& a) {
return a * a;
}
int nxt() {
int x;
cin >> x;
return x;
}
int main() {
int n = nxt();
long long s;
cin >> s;
vector<int> a(n);
generate(a.begin(), a.end(), nxt);
if (accumulate(a.begin(), a.end(), 0ll) < s) {
cout << -1 << '\n';
return 0;
}
int mn = *min_element(a.begin(), a.end());
for (int i = 0; i < int(n); ++i) {
s -= a[i] - mn;
}
s = max(s, 0ll);
cout << mn - (s + n - 1) / n << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long num[1005];
int main() {
long long n, k;
while (~scanf("%lld%lld", &n, &k)) {
long long minn = 0x3f3f3f3f, sum = 0;
for (int i = 0; i < n; i++) {
scanf("%lld", &num[i]);
minn = min(minn, num[i]);
sum += num[i];
}
if (sum < k)
printf("-1\n");
else if (sum == k)
printf("0\n");
else {
long long ans = 0;
for (int i = 0; i < n; i++) ans += num[i] - minn;
if (ans >= k)
printf("%lld\n", minn);
else {
long long tmp = ceil((k - ans) * 1.0 / n);
printf("%lld\n", minn - tmp);
}
}
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long num[1005];
int main() {
long long n, k;
while (~scanf("%lld%lld", &n, &k)) {
long long minn = 0x3f3f3f3f, sum = 0;
for (int i = 0; i < n; i++) {
scanf("%lld", &num[i]);
minn = min(minn, num[i]);
sum += num[i];
}
if (sum < k)
printf("-1\n");
else if (sum == k)
printf("0\n");
else {
long long ans = 0;
for (int i = 0; i < n; i++) ans += num[i] - minn;
if (ans >= k)
printf("%lld\n", minn);
else {
long long tmp = ceil((k - ans) * 1.0 / n);
printf("%lld\n", minn - tmp);
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long N, s, v[1010];
int main() {
cin >> N >> s;
long long minval = numeric_limits<long long>::max();
for (int i = 0; i < N; i++) {
cin >> v[i];
minval = min(minval, v[i]);
}
long long starttotal = 0;
for (int i = 0; i < N; i++) {
starttotal += v[i] - minval;
}
if (starttotal + minval * N < s) {
cout << -1 << endl;
return 0;
}
s -= starttotal;
if (s <= 0) {
cout << minval << endl;
return 0;
}
cout << minval - (long long)ceil((double)s / (double)N) << endl;
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long N, s, v[1010];
int main() {
cin >> N >> s;
long long minval = numeric_limits<long long>::max();
for (int i = 0; i < N; i++) {
cin >> v[i];
minval = min(minval, v[i]);
}
long long starttotal = 0;
for (int i = 0; i < N; i++) {
starttotal += v[i] - minval;
}
if (starttotal + minval * N < s) {
cout << -1 << endl;
return 0;
}
s -= starttotal;
if (s <= 0) {
cout << minval << endl;
return 0;
}
cout << minval - (long long)ceil((double)s / (double)N) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1123;
long long v[N];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
long long s;
cin >> s;
for (int i = 0; i < n; i++) cin >> v[i];
long long sum = 0, mn = LLONG_MAX;
for (int i = 0; i < n; i++) {
mn = min(mn, v[i]);
sum += v[i];
}
if (sum < s) {
cout << -1 << endl;
return 0;
}
long long cur = 0;
for (int i = 0; i < n; i++) {
cur += v[i] - mn;
v[i] = mn;
}
if (cur >= s) {
cout << mn << endl;
return 0;
}
cout << mn - (s - cur + n - 1) / n << endl;
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1123;
long long v[N];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
long long s;
cin >> s;
for (int i = 0; i < n; i++) cin >> v[i];
long long sum = 0, mn = LLONG_MAX;
for (int i = 0; i < n; i++) {
mn = min(mn, v[i]);
sum += v[i];
}
if (sum < s) {
cout << -1 << endl;
return 0;
}
long long cur = 0;
for (int i = 0; i < n; i++) {
cur += v[i] - mn;
v[i] = mn;
}
if (cur >= s) {
cout << mn << endl;
return 0;
}
cout << mn - (s - cur + n - 1) / n << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s;
cin >> n >> s;
long long int min = INT_MAX;
unsigned long long int sum = 0;
long long int i;
long long int arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
if (arr[i] < min) min = arr[i];
}
if (sum < s) {
cout << "-1";
return 0;
}
if (sum == s) {
cout << "0";
return 0;
}
long long int count = 0;
for (i = 0; i < n; i++) {
if (arr[i] > min) count++;
}
for (i = 0; i < n; i++) {
if (count <= 0) break;
if (arr[i] > min) {
count -= 1;
if (s - (arr[i] - min) <= 0) {
cout << min;
return 0;
}
s = s - (arr[i] - min);
arr[i] = min;
}
}
while (s != 0 && min >= 0) {
if (s - (n) <= 0) {
cout << (min - 1);
return 0;
} else {
min--;
s = s - n;
}
}
cout << "-1";
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s;
cin >> n >> s;
long long int min = INT_MAX;
unsigned long long int sum = 0;
long long int i;
long long int arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
if (arr[i] < min) min = arr[i];
}
if (sum < s) {
cout << "-1";
return 0;
}
if (sum == s) {
cout << "0";
return 0;
}
long long int count = 0;
for (i = 0; i < n; i++) {
if (arr[i] > min) count++;
}
for (i = 0; i < n; i++) {
if (count <= 0) break;
if (arr[i] > min) {
count -= 1;
if (s - (arr[i] - min) <= 0) {
cout << min;
return 0;
}
s = s - (arr[i] - min);
arr[i] = min;
}
}
while (s != 0 && min >= 0) {
if (s - (n) <= 0) {
cout << (min - 1);
return 0;
} else {
min--;
s = s - n;
}
}
cout << "-1";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s;
cin >> n >> s;
long long sum = 0LL, min_vol = INT_MAX;
long long arr[n + 1];
for (int i = 0; i < n; i++) {
cin >> arr[i];
min_vol = min(min_vol, arr[i]);
sum += arr[i];
}
if (sum < s)
cout << "-1" << endl;
else {
for (int i = 0; i < n; i++) s -= (arr[i] - min_vol);
if (s <= 0)
cout << min_vol << endl;
else
cout << min_vol - (s + n - 1) / n << endl;
}
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s;
cin >> n >> s;
long long sum = 0LL, min_vol = INT_MAX;
long long arr[n + 1];
for (int i = 0; i < n; i++) {
cin >> arr[i];
min_vol = min(min_vol, arr[i]);
sum += arr[i];
}
if (sum < s)
cout << "-1" << endl;
else {
for (int i = 0; i < n; i++) s -= (arr[i] - min_vol);
if (s <= 0)
cout << min_vol << endl;
else
cout << min_vol - (s + n - 1) / n << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
long long s;
long long v[1005];
bool f(long long x) {
long long sum = 0;
for (int i = 0; i < n; i++) {
if (v[i] > x) {
sum += (v[i] - x);
}
}
return (sum >= s);
}
long long binSearch() {
long long low = 0, high = 1000000001, mid;
for (int i = 0; i < n; i++) {
high = min(high, v[i]);
}
while (high > low) {
mid = (low + high) >> 1;
if (!f(mid))
high = mid;
else
low = mid + 1;
}
return high - 1;
}
int main() {
scanf("%d %lld", &n, &s);
for (int i = 0; i < n; i++) {
scanf("%lld", &v[i]);
}
sort(v, v + n);
reverse(v, v + n);
long long sum = 0;
for (int i = 0; i < n; i++) {
sum += v[i] - v[n - 1];
}
s -= sum;
if (s <= 0) {
printf("%lld\n", v[n - 1]);
} else if ((v[n - 1] * (long long)n) < s) {
printf("-1\n");
} else {
printf("%lld\n", v[n - 1] - (s + n - 1) / n);
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
long long s;
long long v[1005];
bool f(long long x) {
long long sum = 0;
for (int i = 0; i < n; i++) {
if (v[i] > x) {
sum += (v[i] - x);
}
}
return (sum >= s);
}
long long binSearch() {
long long low = 0, high = 1000000001, mid;
for (int i = 0; i < n; i++) {
high = min(high, v[i]);
}
while (high > low) {
mid = (low + high) >> 1;
if (!f(mid))
high = mid;
else
low = mid + 1;
}
return high - 1;
}
int main() {
scanf("%d %lld", &n, &s);
for (int i = 0; i < n; i++) {
scanf("%lld", &v[i]);
}
sort(v, v + n);
reverse(v, v + n);
long long sum = 0;
for (int i = 0; i < n; i++) {
sum += v[i] - v[n - 1];
}
s -= sum;
if (s <= 0) {
printf("%lld\n", v[n - 1]);
} else if ((v[n - 1] * (long long)n) < s) {
printf("-1\n");
} else {
printf("%lld\n", v[n - 1] - (s + n - 1) / n);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
{
long long int n, k;
cin >> n >> k;
long long int ar[n];
for (long long int i = 0; i < n; i++) {
cin >> ar[i];
}
sort(ar, ar + n);
long long int mn = ar[0];
long long int sum = 0;
long long int extras = 0;
for (long long int i = 0; i < n; i++) {
sum += ar[i];
extras = extras + ar[i] - mn;
}
if (k <= sum) {
if (k <= extras)
cout << mn << endl;
else {
long long int rem = k - extras;
long long int fl = rem / n;
if (rem % n != 0) fl++;
cout << mn - fl << endl;
}
} else {
cout << -1 << endl;
}
}
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
{
long long int n, k;
cin >> n >> k;
long long int ar[n];
for (long long int i = 0; i < n; i++) {
cin >> ar[i];
}
sort(ar, ar + n);
long long int mn = ar[0];
long long int sum = 0;
long long int extras = 0;
for (long long int i = 0; i < n; i++) {
sum += ar[i];
extras = extras + ar[i] - mn;
}
if (k <= sum) {
if (k <= extras)
cout << mn << endl;
else {
long long int rem = k - extras;
long long int fl = rem / n;
if (rem % n != 0) fl++;
cout << mn - fl << endl;
}
} else {
cout << -1 << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s, k = 0, m;
cin >> n >> s;
int ar[n];
for (long long j = 0; j < n; j++) {
cin >> ar[j];
k = k + ar[j];
}
m = *min_element(ar, ar + n);
if (k < s)
cout << "-1";
else {
for (long long j = 0; j < n; j++) {
s -= (ar[j] - m);
}
if (s <= 0)
cout << m;
else
cout << (m - (s + n - 1) / n);
}
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s, k = 0, m;
cin >> n >> s;
int ar[n];
for (long long j = 0; j < n; j++) {
cin >> ar[j];
k = k + ar[j];
}
m = *min_element(ar, ar + n);
if (k < s)
cout << "-1";
else {
for (long long j = 0; j < n; j++) {
s -= (ar[j] - m);
}
if (s <= 0)
cout << m;
else
cout << (m - (s + n - 1) / n);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long ceil(long long x, long long y) {
if (!(x % y)) return (x / y);
return (x / y) + 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long n, m, x, y, b;
long long ans = LONG_MIN;
cin >> n >> m;
long long a[n];
long long mi = LONG_MAX;
long long sum = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
mi = min(mi, a[i]);
}
if (sum < m) {
cout << "-1";
return 0;
}
long long diff = 0;
for (long long i = 0; i < n; i++) {
diff += a[i] - mi;
}
if (diff >= m) {
cout << mi << endl;
return 0;
}
cout << (sum - m) / n << endl;
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long ceil(long long x, long long y) {
if (!(x % y)) return (x / y);
return (x / y) + 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long n, m, x, y, b;
long long ans = LONG_MIN;
cin >> n >> m;
long long a[n];
long long mi = LONG_MAX;
long long sum = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
mi = min(mi, a[i]);
}
if (sum < m) {
cout << "-1";
return 0;
}
long long diff = 0;
for (long long i = 0; i < n; i++) {
diff += a[i] - mi;
}
if (diff >= m) {
cout << mi << endl;
return 0;
}
cout << (sum - m) / n << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 15;
const long long MOD = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
int _;
using namespace std;
long long num[1005];
long long N, S;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
while (cin >> N >> S) {
for (int i = 1; i <= N; ++i) cin >> num[i];
sort(num + 1, num + 1 + N);
long long togo = 0;
for (int i = 1; i <= N; ++i) togo += num[i] - num[1];
S -= togo;
S = max(S, 0LL);
if (N * num[1] < S)
cout << -1 << endl;
else
cout << (num[1] - (S / N + (S % N != 0))) << endl;
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 15;
const long long MOD = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
int _;
using namespace std;
long long num[1005];
long long N, S;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
while (cin >> N >> S) {
for (int i = 1; i <= N; ++i) cin >> num[i];
sort(num + 1, num + 1 + N);
long long togo = 0;
for (int i = 1; i <= N; ++i) togo += num[i] - num[1];
S -= togo;
S = max(S, 0LL);
if (N * num[1] < S)
cout << -1 << endl;
else
cout << (num[1] - (S / N + (S % N != 0))) << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s, sum = 0, minn = 0x3f3f3f3f;
cin >> n >> s;
for (int i = 0; i < n; i++) {
long long int a;
cin >> a;
minn = min(minn, a);
sum += a;
}
if (sum < s) {
cout << "-1" << endl;
} else {
cout << min(minn, (sum - s) / n);
}
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s, sum = 0, minn = 0x3f3f3f3f;
cin >> n >> s;
for (int i = 0; i < n; i++) {
long long int a;
cin >> a;
minn = min(minn, a);
sum += a;
}
if (sum < s) {
cout << "-1" << endl;
} else {
cout << min(minn, (sum - s) / n);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int chartointdiff = 48;
bool isprime(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
bool ispossible(long long minn, unsigned long long s,
vector<unsigned long long> arr) {
unsigned long long n = arr.size();
unsigned long long temp = 0;
for (int j = 0; j < n; j++) {
temp += (arr[j] - minn);
}
if (temp >= s) {
return true;
}
return false;
}
void solve() {
unsigned long long n;
cin >> n;
unsigned long long s;
cin >> s;
vector<unsigned long long> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
unsigned long long summ = 0;
for (int i = 0; i < n; i++) {
summ += (arr[i]);
}
if (summ < s) {
cout << -1 << "\n";
return;
} else if (summ == s) {
cout << 0 << "\n";
return;
}
sort(arr.begin(), arr.end());
unsigned long long temp = 0;
unsigned long long low = 0;
long long ans = -1;
unsigned long long high = arr[0];
while (low <= high) {
unsigned long long mid = low + (high - low) / 2;
if (ispossible(mid, s, arr)) {
ans = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
unsigned long long t;
t = 1;
while (t--) {
solve();
}
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int chartointdiff = 48;
bool isprime(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
bool ispossible(long long minn, unsigned long long s,
vector<unsigned long long> arr) {
unsigned long long n = arr.size();
unsigned long long temp = 0;
for (int j = 0; j < n; j++) {
temp += (arr[j] - minn);
}
if (temp >= s) {
return true;
}
return false;
}
void solve() {
unsigned long long n;
cin >> n;
unsigned long long s;
cin >> s;
vector<unsigned long long> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
unsigned long long summ = 0;
for (int i = 0; i < n; i++) {
summ += (arr[i]);
}
if (summ < s) {
cout << -1 << "\n";
return;
} else if (summ == s) {
cout << 0 << "\n";
return;
}
sort(arr.begin(), arr.end());
unsigned long long temp = 0;
unsigned long long low = 0;
long long ans = -1;
unsigned long long high = arr[0];
while (low <= high) {
unsigned long long mid = low + (high - low) / 2;
if (ispossible(mid, s, arr)) {
ans = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
unsigned long long t;
t = 1;
while (t--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s;
long long dp[1100];
long long sum = 0;
cin >> n >> s;
long long minn = 0x3f3f3f3f;
for (int i = 1; i <= n; i++) {
cin >> dp[i];
sum += dp[i];
minn = min(minn, dp[i]);
}
if (sum < s) {
printf("-1\n");
} else if (sum == s) {
printf("0\n");
} else {
int ans = (sum - s) / n;
if (ans < minn) {
cout << ans << endl;
} else {
cout << minn << endl;
}
}
}
| ### Prompt
Create a solution in Cpp for the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s;
long long dp[1100];
long long sum = 0;
cin >> n >> s;
long long minn = 0x3f3f3f3f;
for (int i = 1; i <= n; i++) {
cin >> dp[i];
sum += dp[i];
minn = min(minn, dp[i]);
}
if (sum < s) {
printf("-1\n");
} else if (sum == s) {
printf("0\n");
} else {
int ans = (sum - s) / n;
if (ans < minn) {
cout << ans << endl;
} else {
cout << minn << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long n, s, v[1008], all, now, minn = 1000000008;
int main() {
scanf("%lld %lld", &n, &s);
for (long long i = 1; i <= n; i++) {
scanf("%lld", &v[i]);
all += v[i];
if (v[i] < minn) minn = v[i];
}
if (all < s) {
printf("-1\n");
return 0;
}
now = all - minn * n;
if (s > now) {
if ((s - now) % n == 0) minn += 1;
minn -= (s - now) / n + 1;
}
printf("%lld\n", minn);
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, s, v[1008], all, now, minn = 1000000008;
int main() {
scanf("%lld %lld", &n, &s);
for (long long i = 1; i <= n; i++) {
scanf("%lld", &v[i]);
all += v[i];
if (v[i] < minn) minn = v[i];
}
if (all < s) {
printf("-1\n");
return 0;
}
now = all - minn * n;
if (s > now) {
if ((s - now) % n == 0) minn += 1;
minn -= (s - now) / n + 1;
}
printf("%lld\n", minn);
return 0;
}
``` |
#include <bits/stdc++.h>
int main(void) {
int n;
long long int s;
scanf("%d %lld", &n, &s);
std::vector<long long int> kvass(n);
for (int i = 0; i < n; i++) scanf("%lld", &kvass[i]);
std::sort(kvass.rbegin(), kvass.rend());
long long int remaining = s;
for (int i = 0; i < n - 1; i++) {
long long int difference = kvass[i] - kvass[i + 1];
if (remaining == 0)
break;
else if (difference == 0)
continue;
if (remaining > (i + 1) * difference) {
remaining -= (i + 1) * difference;
} else {
remaining = 0;
printf("%lld", kvass[n - 1]);
return 0;
}
}
if (remaining > kvass[n - 1] * n)
printf("-1");
else
printf("%lld", kvass[n - 1] - (remaining + n - 1) / n);
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
int main(void) {
int n;
long long int s;
scanf("%d %lld", &n, &s);
std::vector<long long int> kvass(n);
for (int i = 0; i < n; i++) scanf("%lld", &kvass[i]);
std::sort(kvass.rbegin(), kvass.rend());
long long int remaining = s;
for (int i = 0; i < n - 1; i++) {
long long int difference = kvass[i] - kvass[i + 1];
if (remaining == 0)
break;
else if (difference == 0)
continue;
if (remaining > (i + 1) * difference) {
remaining -= (i + 1) * difference;
} else {
remaining = 0;
printf("%lld", kvass[n - 1]);
return 0;
}
}
if (remaining > kvass[n - 1] * n)
printf("-1");
else
printf("%lld", kvass[n - 1] - (remaining + n - 1) / n);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, second;
cin >> n >> second;
vector<int> a(n);
long long mini = numeric_limits<int>::max();
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
mini = min(mini, (long long)a[i]);
sum += a[i];
}
if (second > sum) {
cout << -1 << endl;
return 0;
}
sum -= n * mini;
if (second <= sum) {
cout << mini << endl;
return 0;
}
second -= sum;
cout << fixed << setprecision(0)
<< mini - ceil(static_cast<double>(second) / static_cast<double>(n))
<< endl;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, second;
cin >> n >> second;
vector<int> a(n);
long long mini = numeric_limits<int>::max();
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
mini = min(mini, (long long)a[i]);
sum += a[i];
}
if (second > sum) {
cout << -1 << endl;
return 0;
}
sum -= n * mini;
if (second <= sum) {
cout << mini << endl;
return 0;
}
second -= sum;
cout << fixed << setprecision(0)
<< mini - ceil(static_cast<double>(second) / static_cast<double>(n))
<< endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int main() {
long long n, s, z;
cin >> n >> s;
for (long long i = 0; i < n; i++) {
cin >> z;
v.push_back(z);
}
sort(v.begin(), v.end());
for (long long i = n - 1; i > 0; i--) {
if (v[i] - v[0] >= s) {
v[i] = v[i] - s;
s = 0;
break;
} else {
s -= v[i] - v[0];
v[i] = v[0];
}
if (s == 0) break;
}
if (s != 0) {
if (s <= n)
if (v[0] == 0)
cout << -1;
else
cout << v[0] - 1;
else if (n * v[0] < s)
cout << -1;
else if (s % n != 0)
cout << v[0] - (s / n + 1);
else
cout << v[0] - s / n;
} else
cout << v[0];
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int main() {
long long n, s, z;
cin >> n >> s;
for (long long i = 0; i < n; i++) {
cin >> z;
v.push_back(z);
}
sort(v.begin(), v.end());
for (long long i = n - 1; i > 0; i--) {
if (v[i] - v[0] >= s) {
v[i] = v[i] - s;
s = 0;
break;
} else {
s -= v[i] - v[0];
v[i] = v[0];
}
if (s == 0) break;
}
if (s != 0) {
if (s <= n)
if (v[0] == 0)
cout << -1;
else
cout << v[0] - 1;
else if (n * v[0] < s)
cout << -1;
else if (s % n != 0)
cout << v[0] - (s / n + 1);
else
cout << v[0] - s / n;
} else
cout << v[0];
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
long long s;
long long a[1003];
int main() {
scanf("%d%lld", &n, &s);
for (int i = 1; i <= n; i++) scanf("%lld", a + i);
int flag = 0;
sort(a + 1, a + 1 + n);
long long temp = 0;
for (int i = n; i >= 1; i--) {
temp += a[i];
}
if (temp < s) {
printf("-1\n");
return 0;
}
temp = 0;
for (int i = n; i >= 2; i--) {
temp += a[i] - a[1];
}
if (temp < s) {
temp = s - temp;
temp = temp / n + (temp % n != 0);
a[1] -= temp;
}
printf("%lld\n", a[1]);
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
long long s;
long long a[1003];
int main() {
scanf("%d%lld", &n, &s);
for (int i = 1; i <= n; i++) scanf("%lld", a + i);
int flag = 0;
sort(a + 1, a + 1 + n);
long long temp = 0;
for (int i = n; i >= 1; i--) {
temp += a[i];
}
if (temp < s) {
printf("-1\n");
return 0;
}
temp = 0;
for (int i = n; i >= 2; i--) {
temp += a[i] - a[1];
}
if (temp < s) {
temp = s - temp;
temp = temp / n + (temp % n != 0);
a[1] -= temp;
}
printf("%lld\n", a[1]);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long s, k, n, minx = 1e9 + 3, i = 0, t;
int main() {
for (cin >> n >> s; i < n; i++) cin >> k, minx = min(minx, k), t += k;
if (t < s) return cout << -1, 0;
if (t - minx * n < s) return cout << (t - s) / n, 0;
cout << minx;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long s, k, n, minx = 1e9 + 3, i = 0, t;
int main() {
for (cin >> n >> s; i < n; i++) cin >> k, minx = min(minx, k), t += k;
if (t < s) return cout << -1, 0;
if (t - minx * n < s) return cout << (t - s) / n, 0;
cout << minx;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, i;
long long s, sum = 0;
cin >> n >> s;
long long v[n];
for (i = 0; i < n; i++) {
cin >> v[i];
sum += v[i];
}
if (sum < s) {
cout << -1 << endl;
return 0;
}
sort(v, v + n);
for (i = 1; i < n && s > 0; i++) {
s -= (v[i] - v[0]);
}
if (s <= 0) {
cout << v[0] << endl;
return 0;
}
if (s % n == 0)
cout << v[0] - s / n;
else
cout << v[0] - (s / n + 1);
cout << endl;
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, i;
long long s, sum = 0;
cin >> n >> s;
long long v[n];
for (i = 0; i < n; i++) {
cin >> v[i];
sum += v[i];
}
if (sum < s) {
cout << -1 << endl;
return 0;
}
sort(v, v + n);
for (i = 1; i < n && s > 0; i++) {
s -= (v[i] - v[0]);
}
if (s <= 0) {
cout << v[0] << endl;
return 0;
}
if (s % n == 0)
cout << v[0] - s / n;
else
cout << v[0] - (s / n + 1);
cout << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, a[1001], mn = INT_MAX;
long long s, cnt = 0;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mn = min(mn, a[i]);
}
for (int i = 1; i <= n; i++) {
cnt += a[i] - mn;
}
cout << (cnt >= s ? mn
: (mn >= (s - cnt) / n + ((s - cnt) % n == 0 ? 0 : 1)
? mn - (s - cnt) / n - ((s - cnt) % n == 0 ? 0 : 1)
: -1));
}
| ### Prompt
Develop a solution in CPP to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[1001], mn = INT_MAX;
long long s, cnt = 0;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mn = min(mn, a[i]);
}
for (int i = 1; i <= n; i++) {
cnt += a[i] - mn;
}
cout << (cnt >= s ? mn
: (mn >= (s - cnt) / n + ((s - cnt) % n == 0 ? 0 : 1)
? mn - (s - cnt) / n - ((s - cnt) % n == 0 ? 0 : 1)
: -1));
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
void primeFactors(int n) {
while (n % 2 == 0) {
m[2]++;
n = n / 2;
}
for (int i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
m[i]++;
n = n / i;
}
}
if (n > 2) m[n]++;
}
long long gcd(long long a, long long b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
int sum(long long a) {
int sum = 0;
while (a > 0) {
sum = sum + (a % 10);
a = a / 10;
}
return sum;
}
int count_digit(long long n) {
int count = 0;
while (n > 0) {
if (n % 10 == 9) {
count++;
n = n / 10;
continue;
} else {
return count;
n = n / 10;
}
}
}
int binarySearch(int x, int y, long long z, long long v[]) {
int low = x;
int high = y;
int mid = x + (y - x) / 2;
while (low <= high) {
if (v[mid] == z) return mid;
if (v[mid] < z) return binarySearch(mid + 1, high, z, v);
if (v[mid] > z) return binarySearch(low, mid - 1, z, v);
}
return -1;
}
long long modularExponentiation(long long x, long long n, long long M) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return modularExponentiation((x * x) % M, n / 2, M);
else
return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
long long binaryExponentiation(long long x, long long n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return binaryExponentiation(x * x, n / 2);
else
return x * binaryExponentiation(x * x, (n - 1) / 2);
}
int binary(int n) {
int c = 0;
while (n > 0) {
if (n % 2 == 1) {
return pow(2, c);
}
n = n / 2;
c++;
}
}
long long ceil1(long long x, long long y) {
if (x % y == 0)
return x / y;
else
return x / y + 1;
}
set<long long> s;
void genrate(long long n, int len, int max) {
if (len > max) return;
s.insert(n);
genrate(n * 10 + 1, len + 1, max);
genrate(n * 10 + 0, len + 1, max);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tests = 1;
while (tests--) {
int n;
long long s;
cin >> n;
cin >> s;
long long a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long sum = 0;
for (int i = 0; i < n; i++) sum = sum + a[i];
if (sum < s) {
cout << -1;
exit(0);
} else {
sum = 0;
for (int i = n - 1; i > 0; i--) {
if (s > sum + a[i] - a[0]) {
sum = sum + a[i] - a[0];
a[i] = a[0];
} else if (s == sum + a[i] - a[0]) {
cout << a[0];
exit(0);
} else if (s < sum + a[i] - a[0]) {
cout << a[0];
exit(0);
}
}
if (s > sum) {
long long x = s - sum;
if (x % n == 0) {
cout << a[0] - x / n;
} else {
a[0] = a[0] - x / n;
cout << a[0] - 1;
}
}
}
}
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
void primeFactors(int n) {
while (n % 2 == 0) {
m[2]++;
n = n / 2;
}
for (int i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
m[i]++;
n = n / i;
}
}
if (n > 2) m[n]++;
}
long long gcd(long long a, long long b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
int sum(long long a) {
int sum = 0;
while (a > 0) {
sum = sum + (a % 10);
a = a / 10;
}
return sum;
}
int count_digit(long long n) {
int count = 0;
while (n > 0) {
if (n % 10 == 9) {
count++;
n = n / 10;
continue;
} else {
return count;
n = n / 10;
}
}
}
int binarySearch(int x, int y, long long z, long long v[]) {
int low = x;
int high = y;
int mid = x + (y - x) / 2;
while (low <= high) {
if (v[mid] == z) return mid;
if (v[mid] < z) return binarySearch(mid + 1, high, z, v);
if (v[mid] > z) return binarySearch(low, mid - 1, z, v);
}
return -1;
}
long long modularExponentiation(long long x, long long n, long long M) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return modularExponentiation((x * x) % M, n / 2, M);
else
return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
long long binaryExponentiation(long long x, long long n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return binaryExponentiation(x * x, n / 2);
else
return x * binaryExponentiation(x * x, (n - 1) / 2);
}
int binary(int n) {
int c = 0;
while (n > 0) {
if (n % 2 == 1) {
return pow(2, c);
}
n = n / 2;
c++;
}
}
long long ceil1(long long x, long long y) {
if (x % y == 0)
return x / y;
else
return x / y + 1;
}
set<long long> s;
void genrate(long long n, int len, int max) {
if (len > max) return;
s.insert(n);
genrate(n * 10 + 1, len + 1, max);
genrate(n * 10 + 0, len + 1, max);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tests = 1;
while (tests--) {
int n;
long long s;
cin >> n;
cin >> s;
long long a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long sum = 0;
for (int i = 0; i < n; i++) sum = sum + a[i];
if (sum < s) {
cout << -1;
exit(0);
} else {
sum = 0;
for (int i = n - 1; i > 0; i--) {
if (s > sum + a[i] - a[0]) {
sum = sum + a[i] - a[0];
a[i] = a[0];
} else if (s == sum + a[i] - a[0]) {
cout << a[0];
exit(0);
} else if (s < sum + a[i] - a[0]) {
cout << a[0];
exit(0);
}
}
if (s > sum) {
long long x = s - sum;
if (x % n == 0) {
cout << a[0] - x / n;
} else {
a[0] = a[0] - x / n;
cout << a[0] - 1;
}
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
long long total = 0;
long long s;
long long arr[10000];
scanf("%lld%lld", &n, &s);
long long mini = 1e9 + 5;
for (int i = 0; i < n; i++) {
scanf("%lld", &arr[i]);
total += arr[i];
if (arr[i] < mini) mini = arr[i];
}
if (total < s) {
printf("-1");
return 0;
}
long long r = 0;
for (int i = 0; i < n; i++) {
r += (arr[i] - mini);
}
s -= r;
if (s <= 0) {
printf("%lld", mini);
return 0;
}
long long cosa = mini - (s / n);
if (s % n != 0) cosa--;
printf("%lld", cosa);
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
long long total = 0;
long long s;
long long arr[10000];
scanf("%lld%lld", &n, &s);
long long mini = 1e9 + 5;
for (int i = 0; i < n; i++) {
scanf("%lld", &arr[i]);
total += arr[i];
if (arr[i] < mini) mini = arr[i];
}
if (total < s) {
printf("-1");
return 0;
}
long long r = 0;
for (int i = 0; i < n; i++) {
r += (arr[i] - mini);
}
s -= r;
if (s <= 0) {
printf("%lld", mini);
return 0;
}
long long cosa = mini - (s / n);
if (s % n != 0) cosa--;
printf("%lld", cosa);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a == 0 || b == 0) return 0;
if (a == b) return a;
if (a > b) return gcd(a % b, b);
return gcd(a, b % a);
}
long long int max(long long int a, long long int b) {
if (a > b) return a;
return b;
}
long long int min(long long int a, long long int b) {
if (a > b) return b;
return a;
}
long long int dx[4] = {-1, 1, 0, 0};
long long int dy[4] = {0, 0, 1, -1};
long long int ddx[8] = {0, 0, 1, 1, 1, -1, -1, -1};
long long int ddy[8] = {1, -1, 1, -1, 0, 1, -1, 0};
double eps = 0.00000001;
int main() {
ios_base::sync_with_stdio;
cin.tie(0);
cout.tie(0);
long long int n, s;
cin >> n >> s;
long long int arr[n];
for (long long int i = 0; i < n; i++) cin >> arr[i];
long long int Max = -00, Min = 999999999999, sum = 0;
for (long long int i = 0; i < n; i++)
Min = min(Min, arr[i]), Max = max(Max, arr[i]), sum += arr[i];
if (s > sum) {
cout << "-1";
return 0;
}
long long int l = 0, r = Min + 1, mid;
bool change = true;
while (l <= r && change) {
mid = (l + r) / 2;
long long int extra = 0;
for (long long int i = 0; i < n; i++) extra += arr[i] - mid;
if (extra > s) {
if (l != mid)
l = mid;
else
change = false;
} else if (extra == s)
break;
else {
if (r != mid)
r = mid;
else
change = false;
}
}
cout << mid;
int dont_hack_please;
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a == 0 || b == 0) return 0;
if (a == b) return a;
if (a > b) return gcd(a % b, b);
return gcd(a, b % a);
}
long long int max(long long int a, long long int b) {
if (a > b) return a;
return b;
}
long long int min(long long int a, long long int b) {
if (a > b) return b;
return a;
}
long long int dx[4] = {-1, 1, 0, 0};
long long int dy[4] = {0, 0, 1, -1};
long long int ddx[8] = {0, 0, 1, 1, 1, -1, -1, -1};
long long int ddy[8] = {1, -1, 1, -1, 0, 1, -1, 0};
double eps = 0.00000001;
int main() {
ios_base::sync_with_stdio;
cin.tie(0);
cout.tie(0);
long long int n, s;
cin >> n >> s;
long long int arr[n];
for (long long int i = 0; i < n; i++) cin >> arr[i];
long long int Max = -00, Min = 999999999999, sum = 0;
for (long long int i = 0; i < n; i++)
Min = min(Min, arr[i]), Max = max(Max, arr[i]), sum += arr[i];
if (s > sum) {
cout << "-1";
return 0;
}
long long int l = 0, r = Min + 1, mid;
bool change = true;
while (l <= r && change) {
mid = (l + r) / 2;
long long int extra = 0;
for (long long int i = 0; i < n; i++) extra += arr[i] - mid;
if (extra > s) {
if (l != mid)
l = mid;
else
change = false;
} else if (extra == s)
break;
else {
if (r != mid)
r = mid;
else
change = false;
}
}
cout << mid;
int dont_hack_please;
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long INF = 1e7;
signed main() {
cin.tie(0), ios_base::sync_with_stdio(false);
;
long long n, s;
cin >> n >> s;
vector<long long> arr(n);
long long su = 0, mi = 1e18;
for (long long i = 0; i < n; ++i) {
cin >> arr[i];
su += arr[i];
if (mi > arr[i]) {
mi = arr[i];
}
}
su -= s;
if (su < 0) {
cout << -1;
return 0;
}
cout << min(su / n, mi);
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long INF = 1e7;
signed main() {
cin.tie(0), ios_base::sync_with_stdio(false);
;
long long n, s;
cin >> n >> s;
vector<long long> arr(n);
long long su = 0, mi = 1e18;
for (long long i = 0; i < n; ++i) {
cin >> arr[i];
su += arr[i];
if (mi > arr[i]) {
mi = arr[i];
}
}
su -= s;
if (su < 0) {
cout << -1;
return 0;
}
cout << min(su / n, mi);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
int n;
long long s, v[MAXN];
int main() {
ios::sync_with_stdio(0);
while (cin >> n >> s) {
long long S = 0, maxi = 1, mini = 1e9 + 1;
for (int i = (0); i < (n); i++) {
cin >> v[i];
maxi = max(maxi, v[i]);
mini = min(mini, v[i]);
S += v[i];
}
if (S < s)
cout << -1 << endl;
else {
long long a = 0, b = maxi;
while (b - a > 1) {
long long c = (a + b) / 2;
long long ss = 0;
for (int i = (0); i < (n); i++)
if (v[i] > c) ss += v[i] - c;
if (ss >= s)
a = c;
else
b = c;
}
cout << min(mini, a) << endl;
}
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
int n;
long long s, v[MAXN];
int main() {
ios::sync_with_stdio(0);
while (cin >> n >> s) {
long long S = 0, maxi = 1, mini = 1e9 + 1;
for (int i = (0); i < (n); i++) {
cin >> v[i];
maxi = max(maxi, v[i]);
mini = min(mini, v[i]);
S += v[i];
}
if (S < s)
cout << -1 << endl;
else {
long long a = 0, b = maxi;
while (b - a > 1) {
long long c = (a + b) / 2;
long long ss = 0;
for (int i = (0); i < (n); i++)
if (v[i] > c) ss += v[i] - c;
if (ss >= s)
a = c;
else
b = c;
}
cout << min(mini, a) << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<long long int> v;
long long int n, s, x, counter = 0, mini = INT_MAX;
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
counter += x;
mini = min(mini, x);
}
if (counter - s < 0)
cout << -1 << endl;
else
cout << min(mini, (counter - s) / n) << endl;
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<long long int> v;
long long int n, s, x, counter = 0, mini = INT_MAX;
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
counter += x;
mini = min(mini, x);
}
if (counter - s < 0)
cout << -1 << endl;
else
cout << min(mini, (counter - s) / n) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int v[1010];
int main() {
long long n, s;
cin >> n >> s;
long long sum = 0;
long long least = 1e9 + 10;
for (long long i = 0; i < n; i++) {
cin >> v[i];
sum += v[i];
least = min(least, (long long)v[i]);
}
if (sum < s) {
cout << -1 << endl;
return 0;
}
long long remain = sum - s;
long long ans = remain / n;
cout << min(least, ans) << endl;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int v[1010];
int main() {
long long n, s;
cin >> n >> s;
long long sum = 0;
long long least = 1e9 + 10;
for (long long i = 0; i < n; i++) {
cin >> v[i];
sum += v[i];
least = min(least, (long long)v[i]);
}
if (sum < s) {
cout << -1 << endl;
return 0;
}
long long remain = sum - s;
long long ans = remain / n;
cout << min(least, ans) << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long n, s, res, a[1001001], mx, mxi, m, req, cur;
int main() {
cin >> n >> req;
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
}
if (s < req) {
cout << -1;
return 0;
}
sort(a, a + n);
for (int i = 1; i < n; i++) {
cur += (a[i] - a[0]);
}
if (cur < req) {
long long v = req - cur;
long long res = v / n;
if (v % n != 0) res++;
a[0] = a[0] - res;
}
cout << a[0];
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, s, res, a[1001001], mx, mxi, m, req, cur;
int main() {
cin >> n >> req;
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
}
if (s < req) {
cout << -1;
return 0;
}
sort(a, a + n);
for (int i = 1; i < n; i++) {
cur += (a[i] - a[0]);
}
if (cur < req) {
long long v = req - cur;
long long res = v / n;
if (v % n != 0) res++;
a[0] = a[0] - res;
}
cout << a[0];
return 0;
}
``` |
#include <bits/stdc++.h>
long long in() {
char ch;
long long x = 0, f = 1;
while (!isdigit(ch = getchar())) (ch == '-') && (f = -f);
for (x = ch ^ 48; isdigit(ch = getchar());
x = (x << 1) + (x << 3) + (ch ^ 48))
;
return x * f;
}
const long long inf = 999999999999999LL;
const int maxn = 1050;
long long n, k;
long long a[maxn];
long long l, r = inf, t;
bool ok(int mid) {
long long tot = 0;
for (int i = 1; i <= n; i++) tot += std::max(0LL, a[i] - mid);
return tot >= k;
}
int main() {
n = in(), k = in();
for (int i = 1; i <= n; i++) r = std::min(r, a[i] = in()), t += a[i];
if (k > t) {
printf("-1");
return 0;
}
long long ans = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (ok(mid))
ans = mid, l = mid + 1;
else
r = mid - 1;
}
printf("%lld\n", ans);
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
long long in() {
char ch;
long long x = 0, f = 1;
while (!isdigit(ch = getchar())) (ch == '-') && (f = -f);
for (x = ch ^ 48; isdigit(ch = getchar());
x = (x << 1) + (x << 3) + (ch ^ 48))
;
return x * f;
}
const long long inf = 999999999999999LL;
const int maxn = 1050;
long long n, k;
long long a[maxn];
long long l, r = inf, t;
bool ok(int mid) {
long long tot = 0;
for (int i = 1; i <= n; i++) tot += std::max(0LL, a[i] - mid);
return tot >= k;
}
int main() {
n = in(), k = in();
for (int i = 1; i <= n; i++) r = std::min(r, a[i] = in()), t += a[i];
if (k > t) {
printf("-1");
return 0;
}
long long ans = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (ok(mid))
ans = mid, l = mid + 1;
else
r = mid - 1;
}
printf("%lld\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j = 0, k, n, s, sum = 0;
cin >> n >> s;
long long int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
sum = sum + a[i];
}
if (s > sum) {
cout << -1;
return 0;
}
if (s == sum) {
cout << 0;
return 0;
}
sort(a, a + n);
for (i = 0; i < n; i++) {
j = j + (a[i] - a[0]);
}
if (j >= s) {
cout << a[0];
return 0;
} else {
s = s - j;
if (s % n == 0) {
k = s / n;
} else {
k = s / n + 1;
}
cout << a[0] - k;
return 0;
}
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j = 0, k, n, s, sum = 0;
cin >> n >> s;
long long int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
sum = sum + a[i];
}
if (s > sum) {
cout << -1;
return 0;
}
if (s == sum) {
cout << 0;
return 0;
}
sort(a, a + n);
for (i = 0; i < n; i++) {
j = j + (a[i] - a[0]);
}
if (j >= s) {
cout << a[0];
return 0;
} else {
s = s - j;
if (s % n == 0) {
k = s / n;
} else {
k = s / n + 1;
}
cout << a[0] - k;
return 0;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long v[1009], n, s, sum;
long long maxx, minn;
int main() {
minn = 0x3f3f3f3f3f;
sum = 0;
scanf("%lld%lld", &n, &s);
for (int i = 0; i < n; i++) {
scanf("%lld", &v[i]);
sum += v[i];
minn = min(minn, v[i]);
}
if (sum < s) {
printf("-1\n");
return 0;
} else if (sum == s) {
printf("0\n");
return 0;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
ans += abs(minn - v[i]);
}
if (ans >= s) {
printf("%lld\n", minn);
return 0;
} else {
long long ss = s - ans;
ans = ceil(double(ss * 1.0) / (n * 1.0));
printf("%lld\n", minn - ans);
}
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long v[1009], n, s, sum;
long long maxx, minn;
int main() {
minn = 0x3f3f3f3f3f;
sum = 0;
scanf("%lld%lld", &n, &s);
for (int i = 0; i < n; i++) {
scanf("%lld", &v[i]);
sum += v[i];
minn = min(minn, v[i]);
}
if (sum < s) {
printf("-1\n");
return 0;
} else if (sum == s) {
printf("0\n");
return 0;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
ans += abs(minn - v[i]);
}
if (ans >= s) {
printf("%lld\n", minn);
return 0;
} else {
long long ss = s - ans;
ans = ceil(double(ss * 1.0) / (n * 1.0));
printf("%lld\n", minn - ans);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int n, s;
long long int kegs[1002];
bool posible(long long int act) {
long long int suma = 0;
for (int i = 1; i <= n; i++) {
if (kegs[i] > act) {
suma += (kegs[i] - act);
} else {
if (kegs[i] < act) return false;
}
}
if (suma >= s) return true;
return false;
}
int main() {
cin >> n >> s;
for (int i = 1; i <= n; i++) cin >> kegs[i];
long long int ini = 0, fin = 1000000000, mitad;
long long int res = -1;
while (ini <= fin) {
long long int mitad = (ini + fin) / 2;
if (posible(mitad)) {
res = mitad;
ini = mitad + 1;
} else {
fin = mitad - 1;
}
}
cout << res << endl;
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int n, s;
long long int kegs[1002];
bool posible(long long int act) {
long long int suma = 0;
for (int i = 1; i <= n; i++) {
if (kegs[i] > act) {
suma += (kegs[i] - act);
} else {
if (kegs[i] < act) return false;
}
}
if (suma >= s) return true;
return false;
}
int main() {
cin >> n >> s;
for (int i = 1; i <= n; i++) cin >> kegs[i];
long long int ini = 0, fin = 1000000000, mitad;
long long int res = -1;
while (ini <= fin) {
long long int mitad = (ini + fin) / 2;
if (posible(mitad)) {
res = mitad;
ini = mitad + 1;
} else {
fin = mitad - 1;
}
}
cout << res << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long a[n];
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
sort(a, a + n, greater<int>());
if (sum < m) {
cout << "-1\n";
} else if (sum == m) {
cout << "0\n";
} else {
long long avg = (sum - m) / n;
for (int i = 0; i < n; i++) {
if (m <= 0) break;
if (a[i] > avg) {
if (m > a[i] - avg) {
a[i] = avg;
m -= (a[i] - avg);
} else {
a[i] -= m;
m = 0;
}
}
}
if (m < 0) {
cout << "-1\n";
} else {
cout << *min_element(a, a + n) << "\n";
}
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long a[n];
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
sort(a, a + n, greater<int>());
if (sum < m) {
cout << "-1\n";
} else if (sum == m) {
cout << "0\n";
} else {
long long avg = (sum - m) / n;
for (int i = 0; i < n; i++) {
if (m <= 0) break;
if (a[i] > avg) {
if (m > a[i] - avg) {
a[i] = avg;
m -= (a[i] - avg);
} else {
a[i] -= m;
m = 0;
}
}
}
if (m < 0) {
cout << "-1\n";
} else {
cout << *min_element(a, a + n) << "\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[4];
int main() {
int n, i, j;
long long s, sum = 0, min = 1000000010, v, temp;
cin >> n >> s;
for (i = 0; i < n; i++) {
cin >> v;
if (v < min) min = v;
sum += v;
}
if (sum < s)
cout << -1 << endl;
else {
temp = min * n;
if ((sum - temp) >= s)
cout << min << endl;
else {
s -= (sum - temp);
temp = s / n;
if (s % n) temp++;
cout << min - temp << endl;
}
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[4];
int main() {
int n, i, j;
long long s, sum = 0, min = 1000000010, v, temp;
cin >> n >> s;
for (i = 0; i < n; i++) {
cin >> v;
if (v < min) min = v;
sum += v;
}
if (sum < s)
cout << -1 << endl;
else {
temp = min * n;
if ((sum - temp) >= s)
cout << min << endl;
else {
s -= (sum - temp);
temp = s / n;
if (s % n) temp++;
cout << min - temp << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long mod = 1e9 + 7;
vector<long long> v;
long long n, s;
bool check(long long x) {
long long sum = 0;
for (long long i = 0; i < n; i++) {
sum += (v[i] - x);
}
return sum >= s;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
cin >> s;
long long z;
long long sum = 0;
for (long long i = 0; i < n; i++) cin >> z, v.push_back(z), sum += z;
if (sum < s) {
cout << "-1";
return 0;
}
sort(v.begin(), v.end());
long long l = 0;
long long r = v[0];
while (r > l + 1) {
long long m = (l + r) / 2;
if (check(m)) {
l = m;
} else {
r = m;
}
}
if (!check(r))
cout << l << '\n';
else
cout << r;
}
| ### Prompt
In CPP, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long mod = 1e9 + 7;
vector<long long> v;
long long n, s;
bool check(long long x) {
long long sum = 0;
for (long long i = 0; i < n; i++) {
sum += (v[i] - x);
}
return sum >= s;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
cin >> s;
long long z;
long long sum = 0;
for (long long i = 0; i < n; i++) cin >> z, v.push_back(z), sum += z;
if (sum < s) {
cout << "-1";
return 0;
}
sort(v.begin(), v.end());
long long l = 0;
long long r = v[0];
while (r > l + 1) {
long long m = (l + r) / 2;
if (check(m)) {
l = m;
} else {
r = m;
}
}
if (!check(r))
cout << l << '\n';
else
cout << r;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long n, s;
cin >> n >> s;
vector<long long> v;
long long sum = 0;
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
v.push_back(x);
sum += x;
}
if (sum < s) {
cout << -1;
return 0;
}
sort(v.begin(), v.end());
for (int i = n - 1; i >= 0; i--) {
s = s - (v[i] - v[0]);
}
if (s < 0) {
cout << v[0] << '\n';
} else {
if (s % n == 0) {
cout << v[0] - s / n;
} else
cout << v[0] - s / n - 1;
}
}
| ### Prompt
Please create a solution in Cpp to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long n, s;
cin >> n >> s;
vector<long long> v;
long long sum = 0;
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
v.push_back(x);
sum += x;
}
if (sum < s) {
cout << -1;
return 0;
}
sort(v.begin(), v.end());
for (int i = n - 1; i >= 0; i--) {
s = s - (v[i] - v[0]);
}
if (s < 0) {
cout << v[0] << '\n';
} else {
if (s % n == 0) {
cout << v[0] - s / n;
} else
cout << v[0] - s / n - 1;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
if (x < 0) return -x;
return x;
}
template <class T>
T sqr(T a) {
return a * a;
}
const double pi = acos(-1.0);
const double eps = 1e-8;
long long i, j, mn, x, z, sum, ar[100010], n, s;
int main() {
while (2 == scanf("%lld%lld", &n, &s)) {
mn = 1e18;
sum = 0LL;
for (i = 0; i < n; i++) {
scanf("%lld", &x);
mn = min(mn, x);
sum += x;
}
x = sum - (n * mn);
if (x >= s)
printf("%lld\n", mn);
else {
sum = sum - s;
if (sum < 0)
printf("-1\n");
else {
mn = sum / n;
printf("%lld\n", mn);
}
}
}
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
if (x < 0) return -x;
return x;
}
template <class T>
T sqr(T a) {
return a * a;
}
const double pi = acos(-1.0);
const double eps = 1e-8;
long long i, j, mn, x, z, sum, ar[100010], n, s;
int main() {
while (2 == scanf("%lld%lld", &n, &s)) {
mn = 1e18;
sum = 0LL;
for (i = 0; i < n; i++) {
scanf("%lld", &x);
mn = min(mn, x);
sum += x;
}
x = sum - (n * mn);
if (x >= s)
printf("%lld\n", mn);
else {
sum = sum - s;
if (sum < 0)
printf("-1\n");
else {
mn = sum / n;
printf("%lld\n", mn);
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n;
long long int sum, wanted;
int vol[N];
void read() {
cin >> n >> wanted;
for (int i = 0; i < n; i++) cin >> vol[i];
}
void init() {
for (int i = 0; i < n; i++) sum += vol[i];
}
int ans() {
for (int i = 1; i < n; i++) {
int dif = vol[i] - vol[0];
if (wanted <= dif) return vol[0];
wanted -= dif;
vol[i] = vol[0];
}
long long int q;
if (wanted % n == 0)
q = wanted / n;
else
q = (wanted / n) + 1;
return vol[0] - q;
}
int main() {
read();
init();
sort(vol, vol + n);
if (sum < wanted)
cout << -1 << endl;
else
cout << ans() << endl;
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n;
long long int sum, wanted;
int vol[N];
void read() {
cin >> n >> wanted;
for (int i = 0; i < n; i++) cin >> vol[i];
}
void init() {
for (int i = 0; i < n; i++) sum += vol[i];
}
int ans() {
for (int i = 1; i < n; i++) {
int dif = vol[i] - vol[0];
if (wanted <= dif) return vol[0];
wanted -= dif;
vol[i] = vol[0];
}
long long int q;
if (wanted % n == 0)
q = wanted / n;
else
q = (wanted / n) + 1;
return vol[0] - q;
}
int main() {
read();
init();
sort(vol, vol + n);
if (sum < wanted)
cout << -1 << endl;
else
cout << ans() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
long long n, s, sum = 0, m = 9999999999;
scanf("%lld %lld", &n, &s);
for (int i = 0; i < n; i++) {
long long t;
scanf("%lld", &t);
m = m < t ? m : t;
sum += t;
}
if (sum < s)
printf("-1\n");
else
printf("%lld\n", m < (sum - s) / n ? m : (sum - s) / n);
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
int main() {
long long n, s, sum = 0, m = 9999999999;
scanf("%lld %lld", &n, &s);
for (int i = 0; i < n; i++) {
long long t;
scanf("%lld", &t);
m = m < t ? m : t;
sum += t;
}
if (sum < s)
printf("-1\n");
else
printf("%lld\n", m < (sum - s) / n ? m : (sum - s) / n);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int M = 1e4 + 5;
int n, m, w, vis[N], l[N], r[N];
long long a[N], ans[N], s;
int main() {
cin >> n >> s;
long long sum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s) {
cout << -1 << endl;
return 0;
} else if (sum == s) {
cout << 0 << endl;
return 0;
}
sort(a + 1, a + 1 + n);
int now = 1;
sum = s;
while (a[now] == a[1]) {
now++;
}
for (int i = n; i >= now; i--) {
sum -= (a[i] - a[1]);
}
if (sum) {
int cnt = 0;
while (sum > 0) {
sum -= n;
cnt++;
}
cout << a[1] - cnt << endl;
} else {
cout << a[1] << endl;
}
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int M = 1e4 + 5;
int n, m, w, vis[N], l[N], r[N];
long long a[N], ans[N], s;
int main() {
cin >> n >> s;
long long sum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s) {
cout << -1 << endl;
return 0;
} else if (sum == s) {
cout << 0 << endl;
return 0;
}
sort(a + 1, a + 1 + n);
int now = 1;
sum = s;
while (a[now] == a[1]) {
now++;
}
for (int i = n; i >= now; i--) {
sum -= (a[i] - a[1]);
}
if (sum) {
int cnt = 0;
while (sum > 0) {
sum -= n;
cnt++;
}
cout << a[1] - cnt << endl;
} else {
cout << a[1] << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
vector<long long> a;
long long x;
for (long long i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
long long sum = 0;
for (auto &i : a) sum += i;
if (sum < k)
cout << -1;
else {
long long mini = *min_element(a.begin(), a.end());
if (k > sum - n * mini)
cout << (sum - k) / n;
else {
cout << mini;
}
}
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
vector<long long> a;
long long x;
for (long long i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
long long sum = 0;
for (auto &i : a) sum += i;
if (sum < k)
cout << -1;
else {
long long mini = *min_element(a.begin(), a.end());
if (k > sum - n * mini)
cout << (sum - k) / n;
else {
cout << mini;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
long long A[N];
long long fnc(long long h, long long n) {
long long sum = 0;
for (__typeof((n)) i = (1); i <= (n); i++) {
if (A[i] >= h) sum += A[i] - h;
}
return sum;
}
void solve() {
long long n, k, x;
cin >> n >> k;
long long sum = 0;
long long mx = LLONG_MAX;
for (__typeof((n)) i = (1); i <= (n); i++) {
cin >> A[i];
sum += A[i];
mx = min(mx, A[i]);
}
if (k > sum) {
cout << -1 << '\n';
return;
}
long long ans = 0;
long long low = 0;
long long high = mx;
while (high - low >= 0) {
long long mid = (low + high) / 2;
if (fnc(mid, n) >= k) {
ans = mid;
low = mid + 1;
} else
high = mid - 1;
}
cout << ans << '\n';
}
signed main() {
long long t;
ios_base::sync_with_stdio(false);
t = 1;
while (t--) solve();
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
long long A[N];
long long fnc(long long h, long long n) {
long long sum = 0;
for (__typeof((n)) i = (1); i <= (n); i++) {
if (A[i] >= h) sum += A[i] - h;
}
return sum;
}
void solve() {
long long n, k, x;
cin >> n >> k;
long long sum = 0;
long long mx = LLONG_MAX;
for (__typeof((n)) i = (1); i <= (n); i++) {
cin >> A[i];
sum += A[i];
mx = min(mx, A[i]);
}
if (k > sum) {
cout << -1 << '\n';
return;
}
long long ans = 0;
long long low = 0;
long long high = mx;
while (high - low >= 0) {
long long mid = (low + high) / 2;
if (fnc(mid, n) >= k) {
ans = mid;
low = mid + 1;
} else
high = mid - 1;
}
cout << ans << '\n';
}
signed main() {
long long t;
ios_base::sync_with_stdio(false);
t = 1;
while (t--) solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
long long int a[n];
long long int minn = INT_MAX;
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] < minn) minn = a[i];
sum += a[i];
}
long long int x = minn * n;
long long int y = sum - x;
if (sum < m)
cout << "-1" << endl;
else {
if (y >= m)
cout << minn << endl;
else {
m = m - y;
long long int z = ceil(m * 1.0 / n);
cout << minn - z << endl;
}
}
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
long long int a[n];
long long int minn = INT_MAX;
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] < minn) minn = a[i];
sum += a[i];
}
long long int x = minn * n;
long long int y = sum - x;
if (sum < m)
cout << "-1" << endl;
else {
if (y >= m)
cout << minn << endl;
else {
m = m - y;
long long int z = ceil(m * 1.0 / n);
cout << minn - z << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s, i, sum = 0, k = 0, m, d, c = 0;
cin >> n >> s;
long long arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
if (sum < s)
cout << "-1\n";
else if (sum == s)
cout << "0\n";
else {
sort(arr, arr + n);
m = arr[0];
for (i = 0; i < n; i++) {
if (arr[i] > m) {
k += arr[i] - m;
arr[i] -= m;
}
if (k >= s) {
c = 1;
break;
}
}
if (c == 1)
cout << arr[0] << "\n";
else {
d = s - k;
if (d % n == 0)
cout << arr[0] - (d / n) << "\n";
else {
cout << arr[0] - ((d / n) + 1) << "\n";
}
}
}
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s, i, sum = 0, k = 0, m, d, c = 0;
cin >> n >> s;
long long arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
if (sum < s)
cout << "-1\n";
else if (sum == s)
cout << "0\n";
else {
sort(arr, arr + n);
m = arr[0];
for (i = 0; i < n; i++) {
if (arr[i] > m) {
k += arr[i] - m;
arr[i] -= m;
}
if (k >= s) {
c = 1;
break;
}
}
if (c == 1)
cout << arr[0] << "\n";
else {
d = s - k;
if (d % n == 0)
cout << arr[0] - (d / n) << "\n";
else {
cout << arr[0] - ((d / n) + 1) << "\n";
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
long long int a[n];
for (long long int i = 0; i < n; i = i + 1) cin >> a[i];
sort(a, a + n);
long long int extra = 0;
long long int sum = a[0];
for (long long int i = n - 1; i > 0; i = i - 1) {
extra += (a[i] - a[0]);
sum += a[i];
}
if (k > sum) {
cout << -1 << endl;
return 0;
}
if (k <= extra) {
cout << a[0] << endl;
return 0;
}
k = k - extra;
long long int q = k / n;
bool r = k % n;
long long int ans = a[0] - (q + r);
cout << ans << endl;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
long long int a[n];
for (long long int i = 0; i < n; i = i + 1) cin >> a[i];
sort(a, a + n);
long long int extra = 0;
long long int sum = a[0];
for (long long int i = n - 1; i > 0; i = i - 1) {
extra += (a[i] - a[0]);
sum += a[i];
}
if (k > sum) {
cout << -1 << endl;
return 0;
}
if (k <= extra) {
cout << a[0] << endl;
return 0;
}
k = k - extra;
long long int q = k / n;
bool r = k % n;
long long int ans = a[0] - (q + r);
cout << ans << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void _dbg(const char* _s, T _h) {
cerr << _s << " = " << _h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char* _s, T _h, Ts... _t) {
int _b = 0;
while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',') cerr << *_s++;
cerr << " = " << _h << ",";
_dbg(_s + 1, _t...);
}
const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;
void solve() {
int n;
int64_t second;
cin >> n >> second;
vector<int> v(n);
int64_t sum = 0;
int right = INF;
for (auto& el : (v)) {
cin >> el;
sum += el;
right = min(right, el);
}
if (sum < second) {
cout << "-1\n";
return;
}
++right;
int left = 0;
while (right - left > 1) {
int mid = (left + right) / 2;
int64_t amount = 0;
for (int i = 0; i < n; ++i) {
amount += v[i] - mid;
}
if (amount >= second) {
left = mid;
} else {
right = mid;
}
}
cout << left;
}
int main() {
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
int q = 1;
for (int i = 0; i < q; ++i) {
solve();
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void _dbg(const char* _s, T _h) {
cerr << _s << " = " << _h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char* _s, T _h, Ts... _t) {
int _b = 0;
while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',') cerr << *_s++;
cerr << " = " << _h << ",";
_dbg(_s + 1, _t...);
}
const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;
void solve() {
int n;
int64_t second;
cin >> n >> second;
vector<int> v(n);
int64_t sum = 0;
int right = INF;
for (auto& el : (v)) {
cin >> el;
sum += el;
right = min(right, el);
}
if (sum < second) {
cout << "-1\n";
return;
}
++right;
int left = 0;
while (right - left > 1) {
int mid = (left + right) / 2;
int64_t amount = 0;
for (int i = 0; i < n; ++i) {
amount += v[i] - mid;
}
if (amount >= second) {
left = mid;
} else {
right = mid;
}
}
cout << left;
}
int main() {
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
int q = 1;
for (int i = 0; i < q; ++i) {
solve();
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, s;
cin >> n >> s;
vector<ll> v(n);
for (ll i = (0); i < (n); ++i) cin >> v[i];
ll m = *min_element((v).begin(), (v).end());
ll t = 0;
for (ll i = (0); i < (n); ++i) t += v[i];
t -= s;
if (t < 0) {
cout << -1 << endl;
} else {
cout << min(m, t / n) << endl;
}
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, s;
cin >> n >> s;
vector<ll> v(n);
for (ll i = (0); i < (n); ++i) cin >> v[i];
ll m = *min_element((v).begin(), (v).end());
ll t = 0;
for (ll i = (0); i < (n); ++i) t += v[i];
t -= s;
if (t < 0) {
cout << -1 << endl;
} else {
cout << min(m, t / n) << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigMod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
a = abs(a);
b = abs(b);
return (a / gcd(a, b)) * b;
}
template <class T>
inline string int2String(T a) {
ostringstream str;
str << a;
return str.str();
}
const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
void fileIO() {}
int main() {
long long n, s;
scanf("%lld%lld", &n, &s);
vector<long long> v(n);
long long sum = 0;
for (int i = int(0); i < int(n); i++) scanf("%lld", &v[i]), sum += v[i];
if (sum < s) {
puts("-1");
return 0;
}
sort(v.begin(), v.end(), greater<int>());
sum = 0;
for (int i = int(0); i < int(n); i++) {
sum += v[i] - v.back();
v[i] = v.back();
if (sum >= s) {
printf("%lld\n", v.back());
return 0;
}
}
long long need = s - sum;
long long mn = (n + need - 1) / n;
printf("%lld\n", v.back() - mn);
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigMod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
a = abs(a);
b = abs(b);
return (a / gcd(a, b)) * b;
}
template <class T>
inline string int2String(T a) {
ostringstream str;
str << a;
return str.str();
}
const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
void fileIO() {}
int main() {
long long n, s;
scanf("%lld%lld", &n, &s);
vector<long long> v(n);
long long sum = 0;
for (int i = int(0); i < int(n); i++) scanf("%lld", &v[i]), sum += v[i];
if (sum < s) {
puts("-1");
return 0;
}
sort(v.begin(), v.end(), greater<int>());
sum = 0;
for (int i = int(0); i < int(n); i++) {
sum += v[i] - v.back();
v[i] = v.back();
if (sum >= s) {
printf("%lld\n", v.back());
return 0;
}
}
long long need = s - sum;
long long mn = (n + need - 1) / n;
printf("%lld\n", v.back() - mn);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<pair<pair<long long int, long long int>,
pair<long long int, long long int>>,
long long int>
pqr;
map<pair<long long int, long long int>, long long int> xyz;
map<long long int, long long int, greater<long long int>> yz;
vector<pair<long long int, string>> a1;
vector<pair<long long int, long long int>> a2;
vector<pair<long long int, pair<long long int, long long int>>> a3;
bool isSubSequence(string str1, string str2, long long int m, long long int n) {
if (m == 0) return true;
if (n == 0) return false;
if (str1[m - 1] == str2[n - 1])
return isSubSequence(str1, str2, m - 1, n - 1);
return isSubSequence(str1, str2, m, n - 1);
}
long long int fac[5005];
void output2(long long int t) {
if (t > 2) {
cout << "3"
<< " "
<< "1"
<< "\n";
cout << "3"
<< " "
<< "2"
<< "\n";
for (long long int i = 2; i < t - 1; i++) {
cout << "3"
<< " " << i + 2 << "\n";
}
} else {
for (long long int i = 0; i < t - 1; i++) {
cout << "1"
<< " " << i + 2 << "\n";
}
}
}
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long int modInverse(long long int n, long long int p) {
return power(n, p - 2, p);
}
long long int nCrModPFermat(long long int n, long long int r, long long int p,
long long int fac[]) {
if (r == 0) return 1;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, s;
cin >> n >> s;
long long int arr[n + 2];
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
sum = sum + arr[i];
}
if (sum < s) {
cout << "-1\n";
return 0;
}
sort(arr, arr + n);
long long int r = arr[0];
long long int sum1 = 0;
for (long long int i = 0; i < n; i++) {
sum1 = sum1 + abs(arr[i] - r);
}
if (sum1 >= s) {
cout << r << "\n";
return 0;
}
s = s - sum1;
long long int ans = (n * arr[0]) - s;
cout << ans / n;
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<pair<pair<long long int, long long int>,
pair<long long int, long long int>>,
long long int>
pqr;
map<pair<long long int, long long int>, long long int> xyz;
map<long long int, long long int, greater<long long int>> yz;
vector<pair<long long int, string>> a1;
vector<pair<long long int, long long int>> a2;
vector<pair<long long int, pair<long long int, long long int>>> a3;
bool isSubSequence(string str1, string str2, long long int m, long long int n) {
if (m == 0) return true;
if (n == 0) return false;
if (str1[m - 1] == str2[n - 1])
return isSubSequence(str1, str2, m - 1, n - 1);
return isSubSequence(str1, str2, m, n - 1);
}
long long int fac[5005];
void output2(long long int t) {
if (t > 2) {
cout << "3"
<< " "
<< "1"
<< "\n";
cout << "3"
<< " "
<< "2"
<< "\n";
for (long long int i = 2; i < t - 1; i++) {
cout << "3"
<< " " << i + 2 << "\n";
}
} else {
for (long long int i = 0; i < t - 1; i++) {
cout << "1"
<< " " << i + 2 << "\n";
}
}
}
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long int modInverse(long long int n, long long int p) {
return power(n, p - 2, p);
}
long long int nCrModPFermat(long long int n, long long int r, long long int p,
long long int fac[]) {
if (r == 0) return 1;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, s;
cin >> n >> s;
long long int arr[n + 2];
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
sum = sum + arr[i];
}
if (sum < s) {
cout << "-1\n";
return 0;
}
sort(arr, arr + n);
long long int r = arr[0];
long long int sum1 = 0;
for (long long int i = 0; i < n; i++) {
sum1 = sum1 + abs(arr[i] - r);
}
if (sum1 >= s) {
cout << r << "\n";
return 0;
}
s = s - sum1;
long long int ans = (n * arr[0]) - s;
cout << ans / n;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long i, j, flag = 0;
long long n, s;
cin >> n >> s;
long long a[n], sum = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s) {
cout << "-1\n";
return;
}
sort(a, a + n);
while (s != 0) {
long long p = a[n - 1] - a[0];
if (p < s) {
s -= p;
a[n - 1] = a[0];
} else {
a[n - 1] -= s;
s = 0;
}
sort(a, a + n);
if (a[n - 1] == a[0]) break;
}
if (a[n - 1] == a[0]) {
long long p = s / n, q = s % n;
for (i = 0; i < n; i++) a[i] -= p;
for (i = 0; i < q; i++) a[i]--;
sort(a, a + n);
cout << a[0] << endl;
} else
cout << a[0] << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long t = 1;
while (t--) {
solve();
}
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long i, j, flag = 0;
long long n, s;
cin >> n >> s;
long long a[n], sum = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s) {
cout << "-1\n";
return;
}
sort(a, a + n);
while (s != 0) {
long long p = a[n - 1] - a[0];
if (p < s) {
s -= p;
a[n - 1] = a[0];
} else {
a[n - 1] -= s;
s = 0;
}
sort(a, a + n);
if (a[n - 1] == a[0]) break;
}
if (a[n - 1] == a[0]) {
long long p = s / n, q = s % n;
for (i = 0; i < n; i++) a[i] -= p;
for (i = 0; i < q; i++) a[i]--;
sort(a, a + n);
cout << a[0] << endl;
} else
cout << a[0] << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long t = 1;
while (t--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s, A[1005], sum = 0;
scanf("%lld", &n), scanf("%lld", &s);
for (int i = 0; i < n; ++i) {
scanf("%lld", &A[i]);
sum += A[i];
}
if (sum < s) {
printf("-1\n");
return 0;
}
sort(A, A + n);
long long int remainSum = 0;
for (int i = 0; i < n; ++i) {
remainSum += (A[i] - A[0]);
}
if (s <= remainSum) {
printf("%lld\n", A[0]);
return 0;
}
s -= remainSum;
long long int div = s / n;
long long int rem = s % n;
if (rem == 0) {
printf("%lld\n", A[0] - div);
} else
printf("%lld\n", A[0] - div - 1);
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s, A[1005], sum = 0;
scanf("%lld", &n), scanf("%lld", &s);
for (int i = 0; i < n; ++i) {
scanf("%lld", &A[i]);
sum += A[i];
}
if (sum < s) {
printf("-1\n");
return 0;
}
sort(A, A + n);
long long int remainSum = 0;
for (int i = 0; i < n; ++i) {
remainSum += (A[i] - A[0]);
}
if (s <= remainSum) {
printf("%lld\n", A[0]);
return 0;
}
s -= remainSum;
long long int div = s / n;
long long int rem = s % n;
if (rem == 0) {
printf("%lld\n", A[0] - div);
} else
printf("%lld\n", A[0] - div - 1);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long i, j, flag = 0;
long long n, s;
cin >> n >> s;
long long a[n], sum = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s) {
cout << "-1\n";
return;
}
sort(a, a + n);
while (s != 0) {
long long p = a[n - 1] - a[0];
if (p < s) {
s -= p;
a[n - 1] = a[0];
} else {
a[n - 1] -= s;
s = 0;
}
sort(a, a + n);
if (a[n - 1] == a[0]) break;
}
if (a[n - 1] == a[0]) {
long long p = s / n, q = s % n;
for (i = 0; i < n; i++) a[i] -= p;
sort(a, a + n);
if (q > 0)
cout << a[0] - 1 << endl;
else
cout << a[0] << endl;
} else
cout << a[0] << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long t = 1;
while (t--) {
solve();
}
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long i, j, flag = 0;
long long n, s;
cin >> n >> s;
long long a[n], sum = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s) {
cout << "-1\n";
return;
}
sort(a, a + n);
while (s != 0) {
long long p = a[n - 1] - a[0];
if (p < s) {
s -= p;
a[n - 1] = a[0];
} else {
a[n - 1] -= s;
s = 0;
}
sort(a, a + n);
if (a[n - 1] == a[0]) break;
}
if (a[n - 1] == a[0]) {
long long p = s / n, q = s % n;
for (i = 0; i < n; i++) a[i] -= p;
sort(a, a + n);
if (q > 0)
cout << a[0] - 1 << endl;
else
cout << a[0] << endl;
} else
cout << a[0] << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long t = 1;
while (t--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int n, s, a[111111], sum, minn = 11111111111, m, k;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
minn = min(minn, a[i]);
sum += a[i];
}
if (sum < s) {
cout << "-1" << endl;
return 0;
}
for (int i = 0; i < n; i++) m += a[i] - minn;
if (m > s) {
cout << minn << endl;
return 0;
}
k = (s - m) / n;
if ((s - m) % n != 0) k++;
cout << minn - k;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int n, s, a[111111], sum, minn = 11111111111, m, k;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
minn = min(minn, a[i]);
sum += a[i];
}
if (sum < s) {
cout << "-1" << endl;
return 0;
}
for (int i = 0; i < n; i++) m += a[i] - minn;
if (m > s) {
cout << minn << endl;
return 0;
}
k = (s - m) / n;
if ((s - m) % n != 0) k++;
cout << minn - k;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long int gcd(long long int x, long long int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
long long int lcm(long long int a, long long int b) {
return (a * b) / gcd(a, b);
}
const long long int MAXN = (long long int)(1 * 1e6 + 5);
void solve() {
long long int n, tar;
cin >> n >> tar;
vector<long long int> v(n);
long long int sum = 0;
for (long long int i = 0; i < n; i++) cin >> v[i], sum += v[i];
if (sum < tar) {
cout << -1 << '\n';
return;
}
sort(v.begin(), v.end());
cout << min(((sum - tar) / n), v[0]) << '\n';
}
int main() {
fast();
long long int t = 1;
for (long long int i = 0; i < t; i++) {
solve();
}
}
| ### Prompt
Please create a solution in CPP to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long int gcd(long long int x, long long int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
long long int lcm(long long int a, long long int b) {
return (a * b) / gcd(a, b);
}
const long long int MAXN = (long long int)(1 * 1e6 + 5);
void solve() {
long long int n, tar;
cin >> n >> tar;
vector<long long int> v(n);
long long int sum = 0;
for (long long int i = 0; i < n; i++) cin >> v[i], sum += v[i];
if (sum < tar) {
cout << -1 << '\n';
return;
}
sort(v.begin(), v.end());
cout << min(((sum - tar) / n), v[0]) << '\n';
}
int main() {
fast();
long long int t = 1;
for (long long int i = 0; i < t; i++) {
solve();
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long n, s, a[10000], ans, sum, mn = 1e15;
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
mn = min(mn, a[i]);
}
if (sum < s) {
cout << "-1" << endl;
} else {
for (int i = 0; i < n; i++)
if (a[i] > mn) s -= a[i] - mn;
if (s <= 0)
cout << mn << endl;
else
cout << fixed << setprecision(0) << mn - (ceil(s / (n * 1.))) << endl;
}
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, s, a[10000], ans, sum, mn = 1e15;
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
mn = min(mn, a[i]);
}
if (sum < s) {
cout << "-1" << endl;
} else {
for (int i = 0; i < n; i++)
if (a[i] > mn) s -= a[i] - mn;
if (s <= 0)
cout << mn << endl;
else
cout << fixed << setprecision(0) << mn - (ceil(s / (n * 1.))) << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
class Timer {
clock_t start;
string name;
public:
Timer() {
name = "";
start = clock();
}
Timer(string s) {
name = s;
start = clock();
}
~Timer() {
fprintf(stderr, "%s: %.3gs\n", name.c_str(),
1.0 * (clock() - start) / CLOCKS_PER_SEC);
}
};
const double EPS = 1e-9;
const long double PI = acos(-1.0L);
template <typename dtype>
inline dtype sq(dtype a) {
return a * a;
}
template <typename dtype1, typename dtype2>
inline pair<dtype1, dtype2> mp(dtype1 a, dtype2 b) {
return make_pair(a, b);
}
template <typename dtype1, typename dtype2>
inline dtype1 safeMod(dtype1 a, dtype2 m) {
return (a % m + m) % m;
}
template <typename dtype1, typename dtype2>
inline bool isEq(dtype1 a, dtype2 b) {
return abs(a - b) < EPS;
}
template <typename dtype1, typename dtype2, typename dtype3>
inline bool isEq(dtype1 a, dtype2 b, dtype3 eps) {
return abs(a - b) < eps;
}
template <typename dtype>
inline dtype toRad(dtype deg) {
return deg * PI / 180.0;
}
template <typename dtype>
inline dtype toDeg(dtype rad) {
return rad * 180.0 / PI;
}
template <typename dtype>
inline bool isKthBitOn(dtype n, int k) {
assert(n <= numeric_limits<dtype>::max());
assert(k <= numeric_limits<dtype>::digits);
dtype ONE = 1;
return bool((n & (ONE << k)));
}
template <typename dtype>
inline void setKthBit(dtype& n, int k) {
assert(n <= numeric_limits<dtype>::max());
assert(k <= numeric_limits<dtype>::digits);
dtype ONE = 1;
n = (n | (ONE << k));
}
const int oo = 0x3f3f3f3f;
const int MAX = 200010;
const int MOD = 1000000007;
const int precision = 10;
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, s, sum = 0;
long long ara[MAX];
cin >> n >> s;
long long mini = INT_MAX;
for (int i = 0; i < n; i++) {
cin >> ara[i];
sum += ara[i];
mini = min(mini, ara[i]);
}
if (sum < s)
cout << -1;
else {
sum = 0;
for (int i = 0; i < n; i++) {
sum += ara[i] - mini;
}
s -= sum;
s = max(s, 0LL);
mini -= s / n + (s % n != 0);
cout << mini << endl;
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
class Timer {
clock_t start;
string name;
public:
Timer() {
name = "";
start = clock();
}
Timer(string s) {
name = s;
start = clock();
}
~Timer() {
fprintf(stderr, "%s: %.3gs\n", name.c_str(),
1.0 * (clock() - start) / CLOCKS_PER_SEC);
}
};
const double EPS = 1e-9;
const long double PI = acos(-1.0L);
template <typename dtype>
inline dtype sq(dtype a) {
return a * a;
}
template <typename dtype1, typename dtype2>
inline pair<dtype1, dtype2> mp(dtype1 a, dtype2 b) {
return make_pair(a, b);
}
template <typename dtype1, typename dtype2>
inline dtype1 safeMod(dtype1 a, dtype2 m) {
return (a % m + m) % m;
}
template <typename dtype1, typename dtype2>
inline bool isEq(dtype1 a, dtype2 b) {
return abs(a - b) < EPS;
}
template <typename dtype1, typename dtype2, typename dtype3>
inline bool isEq(dtype1 a, dtype2 b, dtype3 eps) {
return abs(a - b) < eps;
}
template <typename dtype>
inline dtype toRad(dtype deg) {
return deg * PI / 180.0;
}
template <typename dtype>
inline dtype toDeg(dtype rad) {
return rad * 180.0 / PI;
}
template <typename dtype>
inline bool isKthBitOn(dtype n, int k) {
assert(n <= numeric_limits<dtype>::max());
assert(k <= numeric_limits<dtype>::digits);
dtype ONE = 1;
return bool((n & (ONE << k)));
}
template <typename dtype>
inline void setKthBit(dtype& n, int k) {
assert(n <= numeric_limits<dtype>::max());
assert(k <= numeric_limits<dtype>::digits);
dtype ONE = 1;
n = (n | (ONE << k));
}
const int oo = 0x3f3f3f3f;
const int MAX = 200010;
const int MOD = 1000000007;
const int precision = 10;
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, s, sum = 0;
long long ara[MAX];
cin >> n >> s;
long long mini = INT_MAX;
for (int i = 0; i < n; i++) {
cin >> ara[i];
sum += ara[i];
mini = min(mini, ara[i]);
}
if (sum < s)
cout << -1;
else {
sum = 0;
for (int i = 0; i < n; i++) {
sum += ara[i] - mini;
}
s -= sum;
s = max(s, 0LL);
mini -= s / n + (s % n != 0);
cout << mini << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long n, s, v[1234], mn, mx = 1e9, sum;
long long liters(long long md) {
long long tmp = 0;
for (int i = 0; i < n; i++) tmp += max(v[i] - md, 0ll);
return tmp;
}
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) cin >> v[i], sum += v[i], mx = min(mx, v[i]);
if (sum < s) return puts("-1") * 0;
while (mx > mn + 1ll) {
long long md = (mn + mx) / 2ll;
if (liters(md) >= s)
mn = md;
else
mx = md;
}
for (long long i = mx; i >= mn; i--) {
if (liters(i) >= s) {
cout << i << endl;
return 0;
}
}
while (1)
;
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, s, v[1234], mn, mx = 1e9, sum;
long long liters(long long md) {
long long tmp = 0;
for (int i = 0; i < n; i++) tmp += max(v[i] - md, 0ll);
return tmp;
}
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) cin >> v[i], sum += v[i], mx = min(mx, v[i]);
if (sum < s) return puts("-1") * 0;
while (mx > mn + 1ll) {
long long md = (mn + mx) / 2ll;
if (liters(md) >= s)
mn = md;
else
mx = md;
}
for (long long i = mx; i >= mn; i--) {
if (liters(i) >= s) {
cout << i << endl;
return 0;
}
}
while (1)
;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int ok(long long int n, long long int k) {
if (n % k == 0)
return (n / k);
else
return (n / k) + 1;
}
long long int ll_sum(long long int n) {
long long int sum = 0;
while (n != 0) sum += (n % 10), n /= 10;
return sum;
}
long long int str_sum(string s) {
long long int sum = 0;
for (long long int i = 0; s[i] != '\0'; i++) sum += (long long int)s[i] - 48;
return sum;
}
long long int power(long long int n, long long int m) {
long long int prod = 1;
for (long long int i = 1; i <= m; i++) prod *= n;
return prod;
}
bool isprime(long long int n) {
if (n < 2)
return 0;
else if (n == 2)
return 1;
for (long long int i = 3; i * i <= n; i += 2)
if (n % i == 0) return 0;
return 1;
}
bool per_sq(long long int n) {
double sq = sqrt(n);
long long int sq1 = sqrt(n);
if (sq - sq1 == 0)
return 1;
else
return 0;
}
int main() {
long long int a, b, c, d, i, j, k, l, m, n, o, p, q, r, u, w, e, f, g, h, t,
ct = 0, ct1 = 0, ct2 = 0, ck = 0, ck1 = 0, ck2 = 0, ln, ln1, start, end,
mid;
long long int a1 = 0, a2 = 0, a3 = 0, a4 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0,
sum = 0, sum1 = 0, max1 = -1000000000000000005,
max2 = -1000000000000000005, min1 = 1000000000000000005,
min2 = 1000000000000000005;
double x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4;
char ch, ch1, ch2;
ios ::sync_with_stdio(false);
cin.tie(0);
;
cin >> n >> m;
vector<long long int> v;
for (i = 0; i < n; i++) cin >> a, sum += a, v.push_back(a);
if (sum < m) {
cout << -1 << endl;
return 0;
}
sort(v.begin(), v.end());
sum = 0;
for (i = 0; i < n; i++) sum += (v[i] - v[0]);
if (sum >= m) {
cout << v[0] << endl;
return 0;
}
a = (m - sum);
a = ok(a, n);
cout << v[0] - a << endl;
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int ok(long long int n, long long int k) {
if (n % k == 0)
return (n / k);
else
return (n / k) + 1;
}
long long int ll_sum(long long int n) {
long long int sum = 0;
while (n != 0) sum += (n % 10), n /= 10;
return sum;
}
long long int str_sum(string s) {
long long int sum = 0;
for (long long int i = 0; s[i] != '\0'; i++) sum += (long long int)s[i] - 48;
return sum;
}
long long int power(long long int n, long long int m) {
long long int prod = 1;
for (long long int i = 1; i <= m; i++) prod *= n;
return prod;
}
bool isprime(long long int n) {
if (n < 2)
return 0;
else if (n == 2)
return 1;
for (long long int i = 3; i * i <= n; i += 2)
if (n % i == 0) return 0;
return 1;
}
bool per_sq(long long int n) {
double sq = sqrt(n);
long long int sq1 = sqrt(n);
if (sq - sq1 == 0)
return 1;
else
return 0;
}
int main() {
long long int a, b, c, d, i, j, k, l, m, n, o, p, q, r, u, w, e, f, g, h, t,
ct = 0, ct1 = 0, ct2 = 0, ck = 0, ck1 = 0, ck2 = 0, ln, ln1, start, end,
mid;
long long int a1 = 0, a2 = 0, a3 = 0, a4 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0,
sum = 0, sum1 = 0, max1 = -1000000000000000005,
max2 = -1000000000000000005, min1 = 1000000000000000005,
min2 = 1000000000000000005;
double x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4;
char ch, ch1, ch2;
ios ::sync_with_stdio(false);
cin.tie(0);
;
cin >> n >> m;
vector<long long int> v;
for (i = 0; i < n; i++) cin >> a, sum += a, v.push_back(a);
if (sum < m) {
cout << -1 << endl;
return 0;
}
sort(v.begin(), v.end());
sum = 0;
for (i = 0; i < n; i++) sum += (v[i] - v[0]);
if (sum >= m) {
cout << v[0] << endl;
return 0;
}
a = (m - sum);
a = ok(a, n);
cout << v[0] - a << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
while (cin >> n >> m) {
long long num, sum = 0, minx = 1000000001;
for (long long i = 0; i < n; i++) {
cin >> num;
sum += num;
if (num < minx) minx = num;
}
if (sum < m)
cout << -1 << endl;
else if (minx < (sum - m) / n) {
cout << minx << endl;
} else
cout << (sum - m) / n << endl;
}
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
while (cin >> n >> m) {
long long num, sum = 0, minx = 1000000001;
for (long long i = 0; i < n; i++) {
cin >> num;
sum += num;
if (num < minx) minx = num;
}
if (sum < m)
cout << -1 << endl;
else if (minx < (sum - m) / n) {
cout << minx << endl;
} else
cout << (sum - m) / n << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int INF = 9e18 + 2e17;
const int inf = 2e9;
const double eps = 1e-10;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
long long int s;
cin >> n >> s;
vector<int> v(n);
long long int z = 0;
for (int i = (int)0; i < (int)n; i++) {
cin >> v[i];
z += v[i];
}
if (z < s)
cout << -1 << endl;
else {
long long int extra = 0;
long long int mn = *min_element((v).begin(), (v).end());
for (int i = (int)0; i < (int)n; i++)
if (v[i] > mn) extra += v[i] - mn;
s -= extra;
int flag = 0;
if (s % n) flag = 1;
if (s > 0) {
s /= n;
mn -= s;
if (flag) mn--;
}
cout << mn << endl;
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int INF = 9e18 + 2e17;
const int inf = 2e9;
const double eps = 1e-10;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
long long int s;
cin >> n >> s;
vector<int> v(n);
long long int z = 0;
for (int i = (int)0; i < (int)n; i++) {
cin >> v[i];
z += v[i];
}
if (z < s)
cout << -1 << endl;
else {
long long int extra = 0;
long long int mn = *min_element((v).begin(), (v).end());
for (int i = (int)0; i < (int)n; i++)
if (v[i] > mn) extra += v[i] - mn;
s -= extra;
int flag = 0;
if (s % n) flag = 1;
if (s > 0) {
s /= n;
mn -= s;
if (flag) mn--;
}
cout << mn << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int s;
cin >> s;
long long int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
long long int smallest = arr[0];
long long int sum = 0;
for (int i = 0; i < n; i++) {
sum = sum + abs(smallest - arr[i]);
}
if (sum >= s) {
cout << smallest;
} else {
s = s - sum;
if (s > n * smallest) {
cout << "-1";
} else {
long long int factor = s / n;
smallest = smallest - factor;
if (s % n == 0)
cout << smallest;
else
cout << smallest - 1;
}
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int s;
cin >> s;
long long int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
long long int smallest = arr[0];
long long int sum = 0;
for (int i = 0; i < n; i++) {
sum = sum + abs(smallest - arr[i]);
}
if (sum >= s) {
cout << smallest;
} else {
s = s - sum;
if (s > n * smallest) {
cout << "-1";
} else {
long long int factor = s / n;
smallest = smallest - factor;
if (s % n == 0)
cout << smallest;
else
cout << smallest - 1;
}
}
}
``` |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T>
void na(vector<T>& a, int n) {
a = vector<T>(n);
for (T& i : a) cin >> i;
}
template <class T>
void printVector(vector<T>& a) {
for (T& i : a) cout << i << ' ';
cout << '\n';
}
template <class T>
vector<T> shrink(vector<T>& x) {
vector<T> vals = x;
sort((vals).begin(), (vals).end());
(vals).resize(unique((vals).begin(), (vals).end()) - (vals).begin());
for (T& i : x)
i = upper_bound((vals).begin(), (vals).end(), i) - vals.begin();
return vals;
}
vector<long long int> a;
long long int s;
bool f(long long int piv) {
long long int cant = 0;
for (long long int i : a) {
if (i > piv) cant += i - piv;
if (i < piv) return 0;
}
return cant >= s;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie();
int n;
cin >> n >> s;
na(a, n);
long long int sol = -1;
long long int st = 0, nd = 1e13;
while (st <= nd) {
long long int piv = (st + nd) / 2;
if (f(piv))
sol = piv, st = piv + 1;
else
nd = piv - 1;
}
cout << sol << '\n';
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T>
void na(vector<T>& a, int n) {
a = vector<T>(n);
for (T& i : a) cin >> i;
}
template <class T>
void printVector(vector<T>& a) {
for (T& i : a) cout << i << ' ';
cout << '\n';
}
template <class T>
vector<T> shrink(vector<T>& x) {
vector<T> vals = x;
sort((vals).begin(), (vals).end());
(vals).resize(unique((vals).begin(), (vals).end()) - (vals).begin());
for (T& i : x)
i = upper_bound((vals).begin(), (vals).end(), i) - vals.begin();
return vals;
}
vector<long long int> a;
long long int s;
bool f(long long int piv) {
long long int cant = 0;
for (long long int i : a) {
if (i > piv) cant += i - piv;
if (i < piv) return 0;
}
return cant >= s;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie();
int n;
cin >> n >> s;
na(a, n);
long long int sol = -1;
long long int st = 0, nd = 1e13;
while (st <= nd) {
long long int piv = (st + nd) / 2;
if (f(piv))
sol = piv, st = piv + 1;
else
nd = piv - 1;
}
cout << sol << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
long long a[MAXN];
int n;
long long s;
int main() {
scanf("%d", &n);
scanf("%lld", &s);
for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
sort(a, a + n);
for (int i = 1; i < n; i++) s -= a[i] - a[0];
if (s <= 0) {
printf("%lld\n", a[0]);
return 0;
}
if (n * a[0] < s) {
printf("-1\n");
return 0;
}
a[0] -= (s + n - 1) / n;
printf("%lld\n", a[0]);
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
long long a[MAXN];
int n;
long long s;
int main() {
scanf("%d", &n);
scanf("%lld", &s);
for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
sort(a, a + n);
for (int i = 1; i < n; i++) s -= a[i] - a[0];
if (s <= 0) {
printf("%lld\n", a[0]);
return 0;
}
if (n * a[0] < s) {
printf("-1\n");
return 0;
}
a[0] -= (s + n - 1) / n;
printf("%lld\n", a[0]);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int mod = 1e9 + 7;
long long n, a[1005];
long long s;
int ck(long long x) {
long long minn = x, now = 0, flag = 0;
for (int i = 1; i <= n; i++) {
if (a[i] >= x) {
now += a[i] - x;
} else {
flag = 1;
break;
}
}
if (now < s || flag) return 0;
return 1;
}
int main() {
scanf("%lld%lld", &n, &s);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
long long l = 0, r = 1e12 + 1, ans = -1;
while (l <= r) {
long long mid = (l + r) >> 1;
if (ck(mid)) {
ans = mid;
l = mid + 1;
} else
r = mid - 1;
}
printf("%lld\n", ans);
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int mod = 1e9 + 7;
long long n, a[1005];
long long s;
int ck(long long x) {
long long minn = x, now = 0, flag = 0;
for (int i = 1; i <= n; i++) {
if (a[i] >= x) {
now += a[i] - x;
} else {
flag = 1;
break;
}
}
if (now < s || flag) return 0;
return 1;
}
int main() {
scanf("%lld%lld", &n, &s);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
long long l = 0, r = 1e12 + 1, ans = -1;
while (l <= r) {
long long mid = (l + r) >> 1;
if (ck(mid)) {
ans = mid;
l = mid + 1;
} else
r = mid - 1;
}
printf("%lld\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1025;
long long p[MAX_N];
int main() {
long long s, n, sum = 0;
scanf("%lld%lld", &n, &s);
for (int i = 1; i <= n; ++i) scanf("%lld", &p[i]), sum += p[i];
sort(p + 1, p + 1 + n);
if (sum < s) {
printf("-1\n");
return 0;
} else {
long long tmp = 0;
for (int i = 1; i <= n; ++i) {
tmp += p[i] - p[1];
}
if (tmp >= s) {
printf("%lld\n", p[1]);
return 0;
} else {
tmp = s - tmp;
long long k = (tmp - 1) / n + 1;
printf("%lld\n", p[1] - k);
}
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1025;
long long p[MAX_N];
int main() {
long long s, n, sum = 0;
scanf("%lld%lld", &n, &s);
for (int i = 1; i <= n; ++i) scanf("%lld", &p[i]), sum += p[i];
sort(p + 1, p + 1 + n);
if (sum < s) {
printf("-1\n");
return 0;
} else {
long long tmp = 0;
for (int i = 1; i <= n; ++i) {
tmp += p[i] - p[1];
}
if (tmp >= s) {
printf("%lld\n", p[1]);
return 0;
} else {
tmp = s - tmp;
long long k = (tmp - 1) / n + 1;
printf("%lld\n", p[1] - k);
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long mod = (long long)1e17 + 7;
long long n, s, v[1005], sum = 0, mn = mod;
long long foo(long long mid) {
long long r1 = sum - (n * mid);
if (r1 >= s)
return 1;
else
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> s;
for (long long i = 1; i <= n; ++i) {
cin >> v[i];
sum += v[i];
mn = min(mn, v[i]);
}
if (sum < s) {
cout << -1;
return 0;
}
long long ans = -1, low = 0, high = mn;
while (low <= high) {
long long mid = (low + high) / 2;
if (foo(mid)) {
low = mid + 1;
ans = max(ans, mid);
} else {
high = mid - 1;
}
}
cout << ans;
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long mod = (long long)1e17 + 7;
long long n, s, v[1005], sum = 0, mn = mod;
long long foo(long long mid) {
long long r1 = sum - (n * mid);
if (r1 >= s)
return 1;
else
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> s;
for (long long i = 1; i <= n; ++i) {
cin >> v[i];
sum += v[i];
mn = min(mn, v[i]);
}
if (sum < s) {
cout << -1;
return 0;
}
long long ans = -1, low = 0, high = mn;
while (low <= high) {
long long mid = (low + high) / 2;
if (foo(mid)) {
low = mid + 1;
ans = max(ans, mid);
} else {
high = mid - 1;
}
}
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
long long n;
cin >> n;
long long s;
cin >> s;
long long sum = 0;
long long mi;
cin >> mi;
sum += mi;
for (long long i = 1; i < n; i++) {
long long t;
cin >> t;
mi = min(mi, t);
sum += t;
}
sum -= s;
if (sum < 0) {
cout << -1;
return 0;
}
long long ans = sum / n;
ans = min(ans, mi);
cout << ans;
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
long long n;
cin >> n;
long long s;
cin >> s;
long long sum = 0;
long long mi;
cin >> mi;
sum += mi;
for (long long i = 1; i < n; i++) {
long long t;
cin >> t;
mi = min(mi, t);
sum += t;
}
sum -= s;
if (sum < 0) {
cout << -1;
return 0;
}
long long ans = sum / n;
ans = min(ans, mi);
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int n = 0;
long long s = 0;
scanf("%d %lld", &n, &s);
long long kegs[n];
memset(kegs, 0, sizeof(kegs));
long long least = -1;
for (int i = 0; i < n; i++) {
int v = 0;
scanf("%d", &v);
kegs[i] = v;
least = (v < least || least == -1) ? v : least;
}
long long container = 0;
long long total = 0;
for (long long x : kegs) {
container += (x - least);
total += x;
}
if (s > total) {
printf("%d\n", -1);
return 0;
}
while (container < s) {
container += n;
least--;
}
printf("%lld\n", least);
}
| ### Prompt
In cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int n = 0;
long long s = 0;
scanf("%d %lld", &n, &s);
long long kegs[n];
memset(kegs, 0, sizeof(kegs));
long long least = -1;
for (int i = 0; i < n; i++) {
int v = 0;
scanf("%d", &v);
kegs[i] = v;
least = (v < least || least == -1) ? v : least;
}
long long container = 0;
long long total = 0;
for (long long x : kegs) {
container += (x - least);
total += x;
}
if (s > total) {
printf("%d\n", -1);
return 0;
}
while (container < s) {
container += n;
least--;
}
printf("%lld\n", least);
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
long long int n, arr[nax];
int main() {
long long int s;
cin >> n >> s;
long long int mini = INF, tot = 0, left = 0;
for (int i = 1; i <= n; i++)
cin >> arr[i], tot += arr[i], mini = min(mini, arr[i]);
for (int i = 1; i <= n; i++) left += abs(arr[i] - mini);
if (tot < s) return cout << -1, 0;
if (left > s) return cout << mini, 0;
int dec = (s - left + n - 1) / n;
cout << mini - dec << "\n";
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
long long int n, arr[nax];
int main() {
long long int s;
cin >> n >> s;
long long int mini = INF, tot = 0, left = 0;
for (int i = 1; i <= n; i++)
cin >> arr[i], tot += arr[i], mini = min(mini, arr[i]);
for (int i = 1; i <= n; i++) left += abs(arr[i] - mini);
if (tot < s) return cout << -1, 0;
if (left > s) return cout << mini, 0;
int dec = (s - left + n - 1) / n;
cout << mini - dec << "\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
long long v[maxn];
int main() {
long long n, s;
scanf("%lld%lld", &n, &s);
long long sum = 0, minn = 1e9 + 7, x;
for (long long i = 0; i < n; i++)
scanf("%lld", &x), sum += x, minn = min(minn, x);
if (sum < s)
printf("-1\n");
else {
long long ans = (sum - s) / n;
printf("%d\n", min(minn, ans));
}
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
long long v[maxn];
int main() {
long long n, s;
scanf("%lld%lld", &n, &s);
long long sum = 0, minn = 1e9 + 7, x;
for (long long i = 0; i < n; i++)
scanf("%lld", &x), sum += x, minn = min(minn, x);
if (sum < s)
printf("-1\n");
else {
long long ans = (sum - s) / n;
printf("%d\n", min(minn, ans));
}
}
``` |
#include <bits/stdc++.h>
void IO(bool inp, bool out) {
if (inp) freopen("k.inp", "r", stdin);
if (out) freopen("k.out", "w", stdout);
}
using namespace std;
short n;
long long a[1001], s;
bool kt(long long u) {
long long t = 0;
for (short i = 1; i <= n; ++i)
if (a[i] < u)
return false;
else
t += a[i] - u;
if (t >= s)
return true;
else
return false;
}
int main() {
IO(0, 0);
scanf("%hd%I64d", &n, &s);
for (short i = 1; i <= n; ++i) scanf("%I64d", &a[i]);
long long l = 0, r = 1000000000, mid, kq = -1;
while (l <= r) {
mid = (l + r) >> 1;
if (kt(mid))
kq = mid, l = mid + 1;
else
r = mid - 1;
}
printf("%I64d", kq);
}
| ### Prompt
Generate a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
void IO(bool inp, bool out) {
if (inp) freopen("k.inp", "r", stdin);
if (out) freopen("k.out", "w", stdout);
}
using namespace std;
short n;
long long a[1001], s;
bool kt(long long u) {
long long t = 0;
for (short i = 1; i <= n; ++i)
if (a[i] < u)
return false;
else
t += a[i] - u;
if (t >= s)
return true;
else
return false;
}
int main() {
IO(0, 0);
scanf("%hd%I64d", &n, &s);
for (short i = 1; i <= n; ++i) scanf("%I64d", &a[i]);
long long l = 0, r = 1000000000, mid, kq = -1;
while (l <= r) {
mid = (l + r) >> 1;
if (kt(mid))
kq = mid, l = mid + 1;
else
r = mid - 1;
}
printf("%I64d", kq);
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool check(vector<long long int> a, long long int mid, long long int k,
long long int &ans) {
long long int n = a.size();
long long int temp = 0;
long long int c = a[n - 1];
;
for (long long int i = n - 1; i >= 0; i--) {
if (a[i] >= mid) {
temp += (a[i] - mid);
c = min(c, mid);
}
}
if (temp >= k) {
ans = max(ans, min(a[0], c));
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k;
cin >> n >> k;
vector<long long int> a(n);
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (k > sum) {
cout << -1;
return 0;
}
sort(a.begin(), a.end());
long long int s = 0;
long long int e = 1000000000;
long long int ans = 0;
while (s <= e) {
long long int mid = s + (e - s) / 2;
if (check(a, mid, k, ans)) {
s = mid + 1;
} else {
e = mid - 1;
}
}
cout << ans;
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool check(vector<long long int> a, long long int mid, long long int k,
long long int &ans) {
long long int n = a.size();
long long int temp = 0;
long long int c = a[n - 1];
;
for (long long int i = n - 1; i >= 0; i--) {
if (a[i] >= mid) {
temp += (a[i] - mid);
c = min(c, mid);
}
}
if (temp >= k) {
ans = max(ans, min(a[0], c));
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k;
cin >> n >> k;
vector<long long int> a(n);
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (k > sum) {
cout << -1;
return 0;
}
sort(a.begin(), a.end());
long long int s = 0;
long long int e = 1000000000;
long long int ans = 0;
while (s <= e) {
long long int mid = s + (e - s) / 2;
if (check(a, mid, k, ans)) {
s = mid + 1;
} else {
e = mid - 1;
}
}
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int n;
long long s;
long long a[1005];
scanf("%d%lld", &n, &s);
int i, j;
long long min = 1e9;
long long Sum = 0;
int flag = 0;
for (i = 0; i < n; i++) {
scanf("%lld", &a[i]);
if (a[i] < min) min = a[i];
Sum += a[i];
}
if (s > Sum) flag = 2;
long long sum = 0;
for (i = 0; i < n; i++) {
sum += a[i] - min;
if (sum > s) {
flag = 1;
break;
}
}
if (flag == 2)
printf("-1\n");
else if (flag)
printf("%lld\n", min);
else {
s = s - sum;
if (s % n == 0) {
min = min - s / n;
} else {
min = min - s / n - 1;
}
printf("%lld\n", min);
}
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int n;
long long s;
long long a[1005];
scanf("%d%lld", &n, &s);
int i, j;
long long min = 1e9;
long long Sum = 0;
int flag = 0;
for (i = 0; i < n; i++) {
scanf("%lld", &a[i]);
if (a[i] < min) min = a[i];
Sum += a[i];
}
if (s > Sum) flag = 2;
long long sum = 0;
for (i = 0; i < n; i++) {
sum += a[i] - min;
if (sum > s) {
flag = 1;
break;
}
}
if (flag == 2)
printf("-1\n");
else if (flag)
printf("%lld\n", min);
else {
s = s - sum;
if (s % n == 0) {
min = min - s / n;
} else {
min = min - s / n - 1;
}
printf("%lld\n", min);
}
}
``` |
#include <bits/stdc++.h>
int n, a[1001], mn = 1e9;
long long s, cnt = 0;
signed main() {
scanf("%d %lld", &n, &s);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (mn > a[i]) mn = a[i];
}
for (int i = 1; i <= n; i++) {
cnt += a[i] - mn;
}
printf("%lld",
(cnt >= s ? mn
: (mn >= (s - cnt) / n + ((s - cnt) % n == 0 ? 0 : 1)
? mn - (s - cnt) / n - ((s - cnt) % n == 0 ? 0 : 1)
: -1)));
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
int n, a[1001], mn = 1e9;
long long s, cnt = 0;
signed main() {
scanf("%d %lld", &n, &s);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (mn > a[i]) mn = a[i];
}
for (int i = 1; i <= n; i++) {
cnt += a[i] - mn;
}
printf("%lld",
(cnt >= s ? mn
: (mn >= (s - cnt) / n + ((s - cnt) % n == 0 ? 0 : 1)
? mn - (s - cnt) / n - ((s - cnt) % n == 0 ? 0 : 1)
: -1)));
}
``` |
#include <bits/stdc++.h>
using namespace std;
void Fast_Read_Out() {
ios_base::sync_with_stdio(0);
cin.tie(), cout.tie();
}
void Random() {
unsigned int seed;
asm("rdtsc" : "=A"(seed));
srand(seed);
}
unsigned int Time() {
unsigned int time = clock() / 1000.00;
return time;
}
const int inf = int(1e9) + 123;
long long a[1001];
int main() {
Random();
Fast_Read_Out();
int n;
long long s;
cin >> n >> s;
long long sum = 0;
for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
if (s > sum) cout << -1 << endl, exit(0);
sort(a + 1, a + n + 1);
for (int i = 2; i <= n && s > 0; i++) s -= (a[i] - a[1]);
if (s <= 0) cout << a[1], exit(0);
if (s % n > 0)
cout << a[1] - s / n - 1;
else
cout << a[1] - s / n << endl;
}
| ### Prompt
Please create a solution in CPP to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void Fast_Read_Out() {
ios_base::sync_with_stdio(0);
cin.tie(), cout.tie();
}
void Random() {
unsigned int seed;
asm("rdtsc" : "=A"(seed));
srand(seed);
}
unsigned int Time() {
unsigned int time = clock() / 1000.00;
return time;
}
const int inf = int(1e9) + 123;
long long a[1001];
int main() {
Random();
Fast_Read_Out();
int n;
long long s;
cin >> n >> s;
long long sum = 0;
for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
if (s > sum) cout << -1 << endl, exit(0);
sort(a + 1, a + n + 1);
for (int i = 2; i <= n && s > 0; i++) s -= (a[i] - a[1]);
if (s <= 0) cout << a[1], exit(0);
if (s % n > 0)
cout << a[1] - s / n - 1;
else
cout << a[1] - s / n << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a[100000];
int main() {
long long n, s, sum = 0, ans, minn = 10000000000000;
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] < minn) minn = a[i];
}
if (sum < s) {
cout << "-1" << endl;
return 0;
}
long long temp = sum - s;
temp = temp / n;
if (minn < temp)
ans = minn;
else
ans = temp;
cout << ans << endl;
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[100000];
int main() {
long long n, s, sum = 0, ans, minn = 10000000000000;
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] < minn) minn = a[i];
}
if (sum < s) {
cout << "-1" << endl;
return 0;
}
long long temp = sum - s;
temp = temp / n;
if (minn < temp)
ans = minn;
else
ans = temp;
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
stack<long long int> st;
long long int binarySearch(long long int l, long long int r, long long int a[],
long long int k) {
if (l <= r) {
long long int mid = l + (r - l) / 2;
if (a[mid] == k)
return mid;
else if (a[mid] > k)
return binarySearch(l, mid - 1, a, k);
else
return binarySearch(mid + 1, r, a, k);
} else
return -1;
}
void solve() {
long long int n, s;
cin >> n >> s;
long long int a[n];
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
long long int v = *min_element(a, a + n);
if (sum < s)
cout << "-1";
else {
for (long long int i = 0; i < n; i++) {
s -= a[i] - v;
}
if (s <= 0)
cout << v;
else
cout << v - (s + n - 1) / n;
}
return;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t = 1;
while (t--) {
solve();
}
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
stack<long long int> st;
long long int binarySearch(long long int l, long long int r, long long int a[],
long long int k) {
if (l <= r) {
long long int mid = l + (r - l) / 2;
if (a[mid] == k)
return mid;
else if (a[mid] > k)
return binarySearch(l, mid - 1, a, k);
else
return binarySearch(mid + 1, r, a, k);
} else
return -1;
}
void solve() {
long long int n, s;
cin >> n >> s;
long long int a[n];
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
long long int v = *min_element(a, a + n);
if (sum < s)
cout << "-1";
else {
for (long long int i = 0; i < n; i++) {
s -= a[i] - v;
}
if (s <= 0)
cout << v;
else
cout << v - (s + n - 1) / n;
}
return;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t = 1;
while (t--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s, sum = 0;
cin >> n >> s;
vector<long long int> u(n);
for (long long int i = 0; i < n; i++) {
cin >> u[i];
sum += u[i];
}
if (sum < s) {
cout << "-1" << endl;
return 0;
}
sort(u.begin(), u.end());
for (long long int i = n - 1; i > 0; i--) {
s -= (u[i] - u[0]);
if (s <= 0) {
cout << u[0] << endl;
return 0;
}
}
long long int d = s / n, r;
if (s % n == 0)
r = 0;
else
r = 1;
cout << u[0] - d - r << endl;
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s, sum = 0;
cin >> n >> s;
vector<long long int> u(n);
for (long long int i = 0; i < n; i++) {
cin >> u[i];
sum += u[i];
}
if (sum < s) {
cout << "-1" << endl;
return 0;
}
sort(u.begin(), u.end());
for (long long int i = n - 1; i > 0; i--) {
s -= (u[i] - u[0]);
if (s <= 0) {
cout << u[0] << endl;
return 0;
}
}
long long int d = s / n, r;
if (s % n == 0)
r = 0;
else
r = 1;
cout << u[0] - d - r << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s, a[1001], somma = 0, minimo = 1000000001;
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
somma += a[i];
minimo = min(minimo, a[i]);
}
if (somma < s)
cout << -1;
else
cout << min(minimo, (somma - s) / n);
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s, a[1001], somma = 0, minimo = 1000000001;
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
somma += a[i];
minimo = min(minimo, a[i]);
}
if (somma < s)
cout << -1;
else
cout << min(minimo, (somma - s) / n);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd1(long long a, long long b) {
if (a == 0) return b;
return gcd1(b % a, a);
}
long long modx(long long base, long long ex) {
long long ans = 1LL, val = base;
while (ex > 0LL) {
if (ex & 1LL) ans = (ans * val) % 1000000009LL;
val = (val * val) % 1000000009LL;
ex = ex >> 1LL;
}
return ans;
}
int n;
long long s, v[1005], minn, sum;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
minn = 20000000000000LL;
for (int i = 1; i <= n; i++) {
cin >> v[i];
minn = min(minn, v[i]);
sum += v[i];
}
if (sum < s) {
cout << "-1" << endl;
return 0;
}
for (int i = 1; i <= n && s > 0; i++) {
s -= (v[i] - minn);
v[i] = minn;
}
if (s <= 0) {
cout << minn << endl;
return 0;
}
if (s % n == 0)
minn -= s / n;
else
minn -= (s / n + 1);
cout << minn << endl;
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd1(long long a, long long b) {
if (a == 0) return b;
return gcd1(b % a, a);
}
long long modx(long long base, long long ex) {
long long ans = 1LL, val = base;
while (ex > 0LL) {
if (ex & 1LL) ans = (ans * val) % 1000000009LL;
val = (val * val) % 1000000009LL;
ex = ex >> 1LL;
}
return ans;
}
int n;
long long s, v[1005], minn, sum;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
minn = 20000000000000LL;
for (int i = 1; i <= n; i++) {
cin >> v[i];
minn = min(minn, v[i]);
sum += v[i];
}
if (sum < s) {
cout << "-1" << endl;
return 0;
}
for (int i = 1; i <= n && s > 0; i++) {
s -= (v[i] - minn);
v[i] = minn;
}
if (s <= 0) {
cout << minn << endl;
return 0;
}
if (s % n == 0)
minn -= s / n;
else
minn -= (s / n + 1);
cout << minn << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
const long long I = 1e18;
int n;
long long s, a[N], l = -1, r = I, c;
bool C(long long k) {
c = 0;
for (int i = 0; i < n; i++)
if (a[i] > k) c += a[i] - k;
return c >= s;
}
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) r = min(r, a[i]);
while (l < r)
if (C((l + r + 1) / 2))
l = (l + r + 1) / 2;
else
r = (l + r - 1) / 2;
cout << l;
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
const long long I = 1e18;
int n;
long long s, a[N], l = -1, r = I, c;
bool C(long long k) {
c = 0;
for (int i = 0; i < n; i++)
if (a[i] > k) c += a[i] - k;
return c >= s;
}
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) r = min(r, a[i]);
while (l < r)
if (C((l + r + 1) / 2))
l = (l + r + 1) / 2;
else
r = (l + r - 1) / 2;
cout << l;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long arr[1010];
int main() {
long long n;
long long s;
cin >> n >> s;
long long mini = (long long)1e15;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
mini = min(arr[i], mini);
sum += arr[i];
}
if (sum < s) {
cout << -1;
return 0;
}
long long u = 0;
for (int i = 0; i < n; i++) {
u += arr[i] - mini;
}
if (u >= s) {
cout << mini;
return 0;
}
sum -= u;
s -= u;
long long ans = sum - s;
mini = ans / n;
cout << mini;
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long arr[1010];
int main() {
long long n;
long long s;
cin >> n >> s;
long long mini = (long long)1e15;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
mini = min(arr[i], mini);
sum += arr[i];
}
if (sum < s) {
cout << -1;
return 0;
}
long long u = 0;
for (int i = 0; i < n; i++) {
u += arr[i] - mini;
}
if (u >= s) {
cout << mini;
return 0;
}
sum -= u;
s -= u;
long long ans = sum - s;
mini = ans / n;
cout << mini;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a[1005];
int main() {
long long n, k, s = 0;
scanf("%lld%lld", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
s += a[i];
}
if (k > s) {
printf("-1\n");
return 0;
}
if (n == 1) {
printf("%lld\n", a[0] - k);
return 0;
}
sort(a, a + n);
long long ans = 0;
for (int i = 1; i < n; i++) {
ans += a[i] - a[0];
}
if (ans < k) {
ans = (k - ans) / n + ((k - ans) % n == 0 ? 0 : 1);
printf("%lld\n", a[0] - ans);
return 0;
} else {
printf("%lld\n", a[0]);
return 0;
}
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[1005];
int main() {
long long n, k, s = 0;
scanf("%lld%lld", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
s += a[i];
}
if (k > s) {
printf("-1\n");
return 0;
}
if (n == 1) {
printf("%lld\n", a[0] - k);
return 0;
}
sort(a, a + n);
long long ans = 0;
for (int i = 1; i < n; i++) {
ans += a[i] - a[0];
}
if (ans < k) {
ans = (k - ans) / n + ((k - ans) % n == 0 ? 0 : 1);
printf("%lld\n", a[0] - ans);
return 0;
} else {
printf("%lld\n", a[0]);
return 0;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, s;
cin >> n >> s;
vector<long long> v(n);
long long sum = 0;
long long mn = 1e9 + 7;
for (int i = 0; i < n; ++i) {
cin >> v[i];
sum += v[i];
mn = min(mn, v[i]);
}
if (sum < s) {
cout << -1 << '\n';
return 0;
}
for (int i = 0; i < n; ++i) {
long long p = min(s, v[i] - mn);
v[i] -= min(s, v[i] - mn);
s -= p;
}
cout << mn - s / n - !!(s % n) << '\n';
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, s;
cin >> n >> s;
vector<long long> v(n);
long long sum = 0;
long long mn = 1e9 + 7;
for (int i = 0; i < n; ++i) {
cin >> v[i];
sum += v[i];
mn = min(mn, v[i]);
}
if (sum < s) {
cout << -1 << '\n';
return 0;
}
for (int i = 0; i < n; ++i) {
long long p = min(s, v[i] - mn);
v[i] -= min(s, v[i] - mn);
s -= p;
}
cout << mn - s / n - !!(s % n) << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
_out << _p.first << ' ' << _p.second << '\n';
return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
_in >> _p.first >> _p.second;
return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
if (_v.empty()) {
return _out;
}
_out << _v.front() << ' ';
for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
_out << *_it << ' ';
}
return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
for (auto &_i : _v) {
_in >> _i;
}
return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
if (_s.empty()) {
return _out;
}
_out << *_s.begin();
for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
_out << ' ' << *_it;
}
return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
if (_s.empty()) {
return _out;
}
_out << *_s.begin();
for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
_out << ' ' << *_it;
}
return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
if (_s.empty()) {
return _out;
}
_out << *_s.begin();
for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
_out << ' ' << *_it;
}
return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
if (_s.empty()) {
return _out;
}
_out << *_s.begin();
for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
_out << ' ' << *_it;
}
return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
if (_m.empty()) {
return _out;
}
for (auto _it : _m) {
_out << _it.first << ": " << _it.second << '\n';
}
return _out;
}
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
struct cord {
int x, y;
};
const int mod = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, s;
cin >> n >> s;
vector<long long> a(n);
long long mini = 1e9;
for (long long i = 0; i < n; i++) {
cin >> a[i];
mini = min(mini, a[i]);
}
long long sum = 0;
long long sum2 = 0;
for (long long i = 0; i < n; i++) {
sum += (a[i] - mini);
sum2 += a[i];
a[i] = mini;
}
if (sum2 < s) {
cout << -1;
return 0;
}
if (sum >= s) {
cout << mini;
} else {
long long diff = s - sum;
long long ans = mini - (diff + n - 1) / n;
cout << ans;
}
}
| ### Prompt
Please create a solution in Cpp to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
_out << _p.first << ' ' << _p.second << '\n';
return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
_in >> _p.first >> _p.second;
return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
if (_v.empty()) {
return _out;
}
_out << _v.front() << ' ';
for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
_out << *_it << ' ';
}
return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
for (auto &_i : _v) {
_in >> _i;
}
return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
if (_s.empty()) {
return _out;
}
_out << *_s.begin();
for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
_out << ' ' << *_it;
}
return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
if (_s.empty()) {
return _out;
}
_out << *_s.begin();
for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
_out << ' ' << *_it;
}
return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
if (_s.empty()) {
return _out;
}
_out << *_s.begin();
for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
_out << ' ' << *_it;
}
return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
if (_s.empty()) {
return _out;
}
_out << *_s.begin();
for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
_out << ' ' << *_it;
}
return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
if (_m.empty()) {
return _out;
}
for (auto _it : _m) {
_out << _it.first << ": " << _it.second << '\n';
}
return _out;
}
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
struct cord {
int x, y;
};
const int mod = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, s;
cin >> n >> s;
vector<long long> a(n);
long long mini = 1e9;
for (long long i = 0; i < n; i++) {
cin >> a[i];
mini = min(mini, a[i]);
}
long long sum = 0;
long long sum2 = 0;
for (long long i = 0; i < n; i++) {
sum += (a[i] - mini);
sum2 += a[i];
a[i] = mini;
}
if (sum2 < s) {
cout << -1;
return 0;
}
if (sum >= s) {
cout << mini;
} else {
long long diff = s - sum;
long long ans = mini - (diff + n - 1) / n;
cout << ans;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxx = 0x3f3f3f3f;
int main() {
long long int n, k, a, m = maxx, s = 0;
cin >> n >> k;
for (long long int i = 0; i < n; i++) {
cin >> a;
m = min(m, a);
s += a;
}
if (s < k) {
cout << -1;
} else {
cout << min(m, (s - k) / n);
}
}
| ### Prompt
Develop a solution in CPP to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxx = 0x3f3f3f3f;
int main() {
long long int n, k, a, m = maxx, s = 0;
cin >> n >> k;
for (long long int i = 0; i < n; i++) {
cin >> a;
m = min(m, a);
s += a;
}
if (s < k) {
cout << -1;
} else {
cout << min(m, (s - k) / n);
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a[1003];
int main() {
long long n, s;
cin >> n >> s;
long long miner = 0x3f3f3f3f3f3f3f3f;
long long sumer = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
sumer += a[i];
miner = min(miner, a[i]);
}
if (sumer < s) {
cout << "-1" << endl;
return 0;
}
sumer = 0;
for (long long i = 0; i < n; i++) {
sumer += a[i] - miner;
a[i] = miner;
}
if (sumer >= s) {
cout << miner << endl;
} else {
long long need = s - sumer;
miner -= need / n;
if (need % n != 0) {
miner--;
}
cout << miner << endl;
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[1003];
int main() {
long long n, s;
cin >> n >> s;
long long miner = 0x3f3f3f3f3f3f3f3f;
long long sumer = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
sumer += a[i];
miner = min(miner, a[i]);
}
if (sumer < s) {
cout << "-1" << endl;
return 0;
}
sumer = 0;
for (long long i = 0; i < n; i++) {
sumer += a[i] - miner;
a[i] = miner;
}
if (sumer >= s) {
cout << miner << endl;
} else {
long long need = s - sumer;
miner -= need / n;
if (need % n != 0) {
miner--;
}
cout << miner << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long n, k, l, r, mid, x;
vector<long long> a;
bool prv(long long mid) {
long long sum = 0;
for (int i = 0; i < n; i++) {
if (a[i] - mid < 0) return false;
}
for (int i = 0; i < n; i++) {
sum += a[i] - mid;
}
if (sum >= k)
return true;
else
return false;
}
int main() {
ios_base::sync_with_stdio(0);
long long sum1 = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
for (int i = 0; i < n; i++) {
sum1 += a[i];
}
if (sum1 < k) {
cout << "-1";
return 0;
}
sum1 = 0;
l = 0;
r = 10000000000000;
while (r - l > 1) {
mid = (l + r) / 2;
if (prv(mid) == true) {
l = mid;
} else {
r = mid;
}
}
if (prv(r) == true) {
cout << r;
} else {
cout << l;
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k, l, r, mid, x;
vector<long long> a;
bool prv(long long mid) {
long long sum = 0;
for (int i = 0; i < n; i++) {
if (a[i] - mid < 0) return false;
}
for (int i = 0; i < n; i++) {
sum += a[i] - mid;
}
if (sum >= k)
return true;
else
return false;
}
int main() {
ios_base::sync_with_stdio(0);
long long sum1 = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
for (int i = 0; i < n; i++) {
sum1 += a[i];
}
if (sum1 < k) {
cout << "-1";
return 0;
}
sum1 = 0;
l = 0;
r = 10000000000000;
while (r - l > 1) {
mid = (l + r) / 2;
if (prv(mid) == true) {
l = mid;
} else {
r = mid;
}
}
if (prv(r) == true) {
cout << r;
} else {
cout << l;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long v[1005], sum, mn;
int main() {
long long n, s;
int i;
scanf("%lld%lld", &n, &s);
sum = 0;
for (i = 0; i < n; i++) {
scanf("%lld", &v[i]);
}
mn = v[0];
for (i = 0; i < n; i++) {
mn = min(v[i], mn);
sum += v[i];
}
if (sum < s) {
printf("-1\n");
return 0;
}
if (sum - n * mn >= s) {
printf("%lld", mn);
return 0;
}
s -= sum - n * mn;
printf("%lld", mn - ((s - 1) / n + 1));
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long v[1005], sum, mn;
int main() {
long long n, s;
int i;
scanf("%lld%lld", &n, &s);
sum = 0;
for (i = 0; i < n; i++) {
scanf("%lld", &v[i]);
}
mn = v[0];
for (i = 0; i < n; i++) {
mn = min(v[i], mn);
sum += v[i];
}
if (sum < s) {
printf("-1\n");
return 0;
}
if (sum - n * mn >= s) {
printf("%lld", mn);
return 0;
}
s -= sum - n * mn;
printf("%lld", mn - ((s - 1) / n + 1));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 2e5 + 30;
const long long MINN = 1e3 + 20;
const long long MOD2 = 998244353ll;
const long long INF = 74592896151251;
const long double EPS = 1e-9;
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
long long mod(long long n) {
while (n < 0) n += MOD;
return n % MOD;
}
long long pow(long long a, long long b) {
return (!b ? 1 : pow(a, b / 2) * pow(a, b / 2) * (b % 2 ? a : 1));
}
long long a[MAXN];
int Main() {
long long n;
cin >> n;
long long s;
cin >> s;
long long d = 0;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s) {
return cout << -1, 0;
}
sort(a, a + n);
for (int i = 1; i < n; i++) d += a[i] - a[0];
if (d >= s) {
cout << a[0];
return 0;
}
s -= d;
long long ans = a[0];
ans -= (s + n - 1) / n;
cout << ans;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int q;
q = 1;
while (q--) Main();
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 2e5 + 30;
const long long MINN = 1e3 + 20;
const long long MOD2 = 998244353ll;
const long long INF = 74592896151251;
const long double EPS = 1e-9;
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
long long mod(long long n) {
while (n < 0) n += MOD;
return n % MOD;
}
long long pow(long long a, long long b) {
return (!b ? 1 : pow(a, b / 2) * pow(a, b / 2) * (b % 2 ? a : 1));
}
long long a[MAXN];
int Main() {
long long n;
cin >> n;
long long s;
cin >> s;
long long d = 0;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s) {
return cout << -1, 0;
}
sort(a, a + n);
for (int i = 1; i < n; i++) d += a[i] - a[0];
if (d >= s) {
cout << a[0];
return 0;
}
s -= d;
long long ans = a[0];
ans -= (s + n - 1) / n;
cout << ans;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int q;
q = 1;
while (q--) Main();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
long long s, sum, mn = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
mn = min(mn, x);
sum += x;
}
if (sum < s)
cout << -1 << endl;
else
cout << min((sum - s) / (long long)n, mn) << endl;
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
long long s, sum, mn = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
mn = min(mn, x);
sum += x;
}
if (sum < s)
cout << -1 << endl;
else
cout << min((sum - s) / (long long)n, mn) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
lint liters(int l, vector<int> &arr) {
lint sum = 0;
for (int k : arr) sum += (lint)(k - l);
return sum;
}
int main() {
int n, m = 1000000010;
lint s;
vector<int> arr;
cin >> n >> s;
arr.resize(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
m = min(m, arr[i]);
}
if (s > liters(0, arr))
cout << -1 << endl;
else {
int start = 0, end = m;
while (start < end) {
int mid = (start + end) / 2 + 1;
if (s <= liters(mid, arr))
start = mid;
else
end = mid - 1;
}
cout << start << endl;
}
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
lint liters(int l, vector<int> &arr) {
lint sum = 0;
for (int k : arr) sum += (lint)(k - l);
return sum;
}
int main() {
int n, m = 1000000010;
lint s;
vector<int> arr;
cin >> n >> s;
arr.resize(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
m = min(m, arr[i]);
}
if (s > liters(0, arr))
cout << -1 << endl;
else {
int start = 0, end = m;
while (start < end) {
int mid = (start + end) / 2 + 1;
if (s <= liters(mid, arr))
start = mid;
else
end = mid - 1;
}
cout << start << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long v[1010];
int main() {
long long s;
long long n, mn = 1e17, sum = 0;
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> v[i];
sum += v[i];
mn = min(v[i], mn);
}
if (sum < s) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) s -= (v[i] - mn);
if (s <= 0)
cout << mn;
else
cout << mn - (s + n - 1) / n;
}
| ### Prompt
Create a solution in CPP for the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long v[1010];
int main() {
long long s;
long long n, mn = 1e17, sum = 0;
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> v[i];
sum += v[i];
mn = min(v[i], mn);
}
if (sum < s) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) s -= (v[i] - mn);
if (s <= 0)
cout << mn;
else
cout << mn - (s + n - 1) / n;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long n, s, i, j, a[10001], MIN;
long long m_min(long long a, long long b) {
if (a < b)
return a;
else
return b;
}
int main() {
scanf("%lld%lld", &n, &s);
for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
long long sum = 0;
MIN = 1e18;
for (i = 1; i <= n; i++) {
sum += a[i];
MIN = m_min(MIN, a[i]);
}
if (sum < s)
printf("-1\n");
else
printf("%lld\n", m_min(MIN, (sum - s) / n));
}
| ### Prompt
Create a solution in CPP for the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, s, i, j, a[10001], MIN;
long long m_min(long long a, long long b) {
if (a < b)
return a;
else
return b;
}
int main() {
scanf("%lld%lld", &n, &s);
for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
long long sum = 0;
MIN = 1e18;
for (i = 1; i <= n; i++) {
sum += a[i];
MIN = m_min(MIN, a[i]);
}
if (sum < s)
printf("-1\n");
else
printf("%lld\n", m_min(MIN, (sum - s) / n));
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s;
cin >> n >> s;
long long a[n];
long long sum = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s)
cout << "-1";
else {
long x = sizeof(a) / sizeof(a[0]);
sort(a, a + x);
long long it = n - 1;
while (s > 0) {
if (it == 0) {
break;
} else {
s = s - (a[it] - a[0]);
a[it] -= (a[it] - a[0]);
it--;
}
}
if (it == 0 && s > 0) {
long long ax;
if (s % n == 0)
ax = (s / n);
else
ax = (s / n) + 1;
cout << (a[0] - ax);
} else
cout << a[0];
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s;
cin >> n >> s;
long long a[n];
long long sum = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum < s)
cout << "-1";
else {
long x = sizeof(a) / sizeof(a[0]);
sort(a, a + x);
long long it = n - 1;
while (s > 0) {
if (it == 0) {
break;
} else {
s = s - (a[it] - a[0]);
a[it] -= (a[it] - a[0]);
it--;
}
}
if (it == 0 && s > 0) {
long long ax;
if (s % n == 0)
ax = (s / n);
else
ax = (s / n) + 1;
cout << (a[0] - ax);
} else
cout << a[0];
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using lld = long long int;
int main() {
lld n, s;
cin >> n >> s;
vector<lld> V(n);
lld su = 0;
for (int i = 0; i < n; i++) {
lld x;
cin >> x;
su += x;
V[i] = x;
}
if (su < s) {
cout << -1 << endl;
} else {
lld fr = 0, mn = *min_element(V.begin(), V.end());
for (int i = 0; i < n; i++) {
fr += V[i] - mn;
V[i] = mn;
}
if (fr >= s) {
cout << mn << endl;
} else {
s -= fr;
if (s % n == 0) {
cout << mn - s / n << endl;
} else {
cout << mn - s / n - 1 << endl;
}
}
}
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using lld = long long int;
int main() {
lld n, s;
cin >> n >> s;
vector<lld> V(n);
lld su = 0;
for (int i = 0; i < n; i++) {
lld x;
cin >> x;
su += x;
V[i] = x;
}
if (su < s) {
cout << -1 << endl;
} else {
lld fr = 0, mn = *min_element(V.begin(), V.end());
for (int i = 0; i < n; i++) {
fr += V[i] - mn;
V[i] = mn;
}
if (fr >= s) {
cout << mn << endl;
} else {
s -= fr;
if (s % n == 0) {
cout << mn - s / n << endl;
} else {
cout << mn - s / n - 1 << endl;
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, sum, sum1, ans, sub, arr[1000000];
int main() {
scanf("%lld %lld", &n, &m);
for (i = 0; i < n; i++) {
scanf("%lld", &arr[i]);
sum = sum + arr[i];
}
if (sum < m) {
printf("-1\n");
} else if (sum == m) {
printf("0\n");
} else {
sort(arr, arr + n);
sum1 = 0;
for (i = 1; i < n; i++) {
sum1 = sum1 + (abs(arr[i] - arr[0]));
}
if (sum1 >= m) {
printf("%lld", arr[0]);
} else {
sum1 = m - sum1;
if (sum1 % n == 0) {
sub = sum1 / n;
} else {
sub = (sum1 / n) + 1;
}
ans = arr[0] - sub;
printf("%lld\n", ans);
}
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, sum, sum1, ans, sub, arr[1000000];
int main() {
scanf("%lld %lld", &n, &m);
for (i = 0; i < n; i++) {
scanf("%lld", &arr[i]);
sum = sum + arr[i];
}
if (sum < m) {
printf("-1\n");
} else if (sum == m) {
printf("0\n");
} else {
sort(arr, arr + n);
sum1 = 0;
for (i = 1; i < n; i++) {
sum1 = sum1 + (abs(arr[i] - arr[0]));
}
if (sum1 >= m) {
printf("%lld", arr[0]);
} else {
sum1 = m - sum1;
if (sum1 % n == 0) {
sub = sum1 / n;
} else {
sub = (sum1 / n) + 1;
}
ans = arr[0] - sub;
printf("%lld\n", ans);
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long A[2222];
int n;
long long kvass(long long c) {
long long ans = 0;
for (int i = 0; i < (n); i++) ans += A[i] > c ? A[i] - c : 0;
return ans;
}
long long bs(long long lo, long long hi, long long s) {
if (lo >= hi) return lo;
long long c = (lo + hi) / 2;
if (kvass(c) >= s)
return bs(c + 1, hi, s);
else
return bs(lo, c, s);
}
int main() {
long long s;
scanf("%i %lli", &n, &s);
for (int i = 0; i < (n); i++) scanf(" %lli", A + i);
long long tot = 0;
for (int i = 0; i < (n); i++) tot += A[i];
if (s > tot) {
printf("-1\n");
return 0;
}
long long ans = bs(0, 0x7fffffffL, s) - 1;
for (int i = 0; i < (n); i++)
if (A[i] < ans) ans = A[i];
printf("%lli\n", ans);
}
| ### Prompt
Create a solution in Cpp for the following problem:
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by s liters of kvass.
Input
The first line contains two integers n and s (1 β€ n β€ 10^3, 1 β€ s β€ 10^{12}) β the number of kegs and glass volume.
The second line contains n integers v_1, v_2, β¦, v_n (1 β€ v_i β€ 10^9) β the volume of i-th keg.
Output
If the Fair Nut cannot pour his glass by s liters of kvass, print -1. Otherwise, print a single integer β how much kvass in the least keg can be.
Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
Note
In the first example, the answer is 3, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3 liters of kvass in each keg.
In the second example, the answer is 2, the Fair Nut can take 3 liters from the first keg and 1 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 7 liters, so the answer is -1.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long A[2222];
int n;
long long kvass(long long c) {
long long ans = 0;
for (int i = 0; i < (n); i++) ans += A[i] > c ? A[i] - c : 0;
return ans;
}
long long bs(long long lo, long long hi, long long s) {
if (lo >= hi) return lo;
long long c = (lo + hi) / 2;
if (kvass(c) >= s)
return bs(c + 1, hi, s);
else
return bs(lo, c, s);
}
int main() {
long long s;
scanf("%i %lli", &n, &s);
for (int i = 0; i < (n); i++) scanf(" %lli", A + i);
long long tot = 0;
for (int i = 0; i < (n); i++) tot += A[i];
if (s > tot) {
printf("-1\n");
return 0;
}
long long ans = bs(0, 0x7fffffffL, s) - 1;
for (int i = 0; i < (n); i++)
if (A[i] < ans) ans = A[i];
printf("%lli\n", ans);
}
``` |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.