Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
# back to beginning import math n, s = input(). split() n, s = int(n), int(s) a = [int(i) for i in input(). split()] a.sort() for i in range (n) : if a[i] > a[0] : s -= a[i] - a[0] if s <= 0 : print(a[0]) break if a[0] * n < s : print (-1) elif s > 0: print(a[0] - math.ceil(s / n))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
from math import ceil n, s = map(int, input().split()) a = list(map(int, input().split())) sm = min(a) diff = 0 if sum(a) < s: print(-1) exit(0) for i in a: diff += i - sm # print(diff) if diff >= s: print(sm) else: rem = s - diff if diff == 0: print(a[0] - int(ceil(s/n))) # print(rem) else: to_rem = int(ceil(rem/n)) print(sm - to_rem)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = map(int, input().split()) l = [*map(int, input().split())] sm = sum(l) if sm < s: print(-1) exit(0) m = min(l) s -= sm - m * n if s <= 0: print(m) else: print(m - (s + n - 1)//n)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n,s=map(int,input().split()) v=list(map(int,input().split())) a=sum(v) if a<s: print(-1) else: z=min(v) a-=s print(min(z,a//n))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; } } }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import java.lang.reflect.Array; import java.util.*; import java.lang.*; import java.math.*; import java.io.*; /* abhi2601 */ public class Q1 implements Runnable{ final static long mod = (long)1e9 + 7; static class pair{ int a,b; pair(int a,int b){ this.a=a; this.b=b; } } public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n=sc.nextInt(); long s=sc.nextLong(),z=0; ArrayList<Long>al=new ArrayList<>(); for(int i=0;i<n;i++){ al.add(sc.nextLong()); z+=al.get(i); } if(z<s) w.println("-1"); else if(z==s) w.println("0"); else{ long min=Collections.min(al),ans=0; for(int i=0;i<n;i++) ans+=(al.get(i)-min); if(ans>=s) w.println(min); else{ ans=s-ans; min-=Math.ceil((double)ans/n); w.println(min); } } w.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new Q1(),"q1",1<<26).start(); } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
import math n,s=map(int,input().split()) v=list(map(int,input().split())) x=sum(v) if s>x: print(-1) else: a=min(v) if s<x-n*a: print(a) else: b=x-n*a c=s-b print(a-math.ceil(c/n))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n,s = map(int,raw_input().split()) numbers = list(map(int,raw_input().split())) total = 0 minimum = 10000000000 for i in numbers: if i < minimum: minimum = i total += i low = 0 high = minimum middle = (low + high)>>1 if s <= total: while (((total - n*middle) < s) or (total - (n*(middle+1) - 1) > s)) and (high > low): if (s > (total - n*middle)): high = middle elif s < (total - (n*(middle+1) -1)): low = middle + 1 middle = (high + low)>>1 print middle else: print -1
PYTHON
1084_B. Kvass and the Fair Nut
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.
2
8
from sys import stdin, stdout from math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial n, s = map(int, stdin.readline().split()) values = list(map(int, stdin.readline().split())) l, r = -1, min(values) + 1 while r - l > 1: m = (l + r) >> 1 cnt = 0 for v in values: cnt += v - m if cnt >= s: l = m else: r = m if l == -1: stdout.write('-1\n') else: stdout.write(str(l) + '\n')
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import math n, s = map(int, input().split()) arr = list(map(int, input().split())) m = min(arr) suum = sum(arr) if suum >= s: print(min((suum-s)//n, m)) else: print(-1)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.util.Arrays; import java.util.Scanner; /** * @Created by sbhowmik on 10/12/18 */ public class KvassAndTheFairNut { public static void main(String []args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); long t = scanner.nextLong(); int i = 0; long arr[] = new long[n]; long minValueCheck = Long.MAX_VALUE; while (i < n) { arr[i] = scanner.nextLong(); if (arr[i] < minValueCheck) { minValueCheck = arr[i]; } i++; } //Arrays.sort(arr); long sum = 0; for (i = arr.length - 1; i >= 0; i--) { sum = sum + (arr[i] - minValueCheck); } if (sum < 0) { System.out.println(-1); } else { if (sum >= t) { System.out.println(minValueCheck); } else { long sumLeft = t - sum; long minVal = minValueCheck; long index = sumLeft/n; long mod = sumLeft%n; if (mod == 0) { minVal = minVal - index; } else { minVal = minVal - index - 1; } if(minVal >= 0) { System.out.println(minVal); } else { System.out.println(-1); } } } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
from math import ceil n, s = map(int, input().split()) l = list(map(int, input().split())) ans = sum(l) if n == 1 and s == l[0]: print(0) exit(0) if ans < s: print(-1) exit(0) minimal = min(l) ans = 0 for i in range(len(l)): if l[i] > minimal: if ans + l[i] - minimal >= s: l[i] -= l[i] - minimal print(min(l)) exit(0) ans += l[i] - minimal l[i] -= l[i] - minimal print(max(l) - (ceil((s - ans) / len(l))))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = [int(s) for s in input().split()] a = [int(s) for s in input().split()] summa = sum(a) if summa < s: print(-1) else: answer = (summa - s)//len(a) if answer > min(a): answer = min(a) print(answer)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = map(int, input().split()) a = list(map(int, input().split())) if sum(a)<s: print(-1) elif (sum(a)-s)//n>min(a): print(min(a)) else: print((sum(a)-s)//n)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
from math import ceil def kvass(arr,s): if sum(arr) < s: return -1 n = len(arr) cap = 0 m = min(arr) for i in xrange(n): amt = arr[i]-m cap += amt arr[i] -= amt if cap >= s: return m extra = s-cap count = ceil(float(extra)/n) return int(m-count) n,s = map(int, raw_input().split()) arr = map(int, raw_input().split()) res = kvass(arr,s) print res
PYTHON
1084_B. Kvass and the Fair Nut
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.
2
8
//package dec18; import java.util.Scanner; public class Kvass1084B { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scn=new Scanner(System.in); long n=scn.nextLong(); long s=scn.nextLong(); long[] arr=new long[(int)n]; long sum=0; for(int i=0; i<n; i++) { arr[i]=scn.nextLong(); sum=sum+arr[i]; } long count=s; long minindex=0; long min=Long.MAX_VALUE; for(int i=0; i<n; i++) { if(arr[i]<min) { min=arr[i]; minindex=i; } } if(sum>=s) { for(int i=0; i<n; i++) { s=s-(arr[i]-min); } if(s<=0) { System.out.println(min); } else { long a1=(s+n-1)/n; long a2=min-a1; System.out.println((long)Math.floor(a2)); } } else { System.out.println("-1"); } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class B_526 { public static void main(String[] args) { FastReader scan = new FastReader(); PrintWriter out = new PrintWriter(System.out); int n = scan.nextInt(); long m = scan.nextLong(); int[] a = new int[n]; long sum = 0; long min = Integer.MAX_VALUE; for(int i = 0; i < n; i++) { a[i] = scan.nextInt(); sum += a[i]; min = Math.min(min, a[i]); } if(sum < m) { out.println(-1); } else { Arrays.sort(a); //long ans = 0; long r = 0; for(int i : a) r += i-min; long left = m - r; left = Math.max(0, left); long s = (long) Math.ceil(1.0*left/n); out.println(min - s); } out.close(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
ss = 0 n, s = map(int, input().split()) v = list(map(int, input().split())) m,ss = min(v), sum(v) if ss < s: print(-1) else: print(min(m, (ss-s)//n))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import math from sys import stdin, stdout input = stdin.readline listin = lambda : list(map(int, input().split())) mapin = lambda : map(int, input().split()) n, s = mapin() v = listin() if sum(v) < s: print(-1) elif sum(v) == s: print(0) else: v.sort() t = sum(v) - v[0]*n if s <= t: print(v[0]) else: s-=t v = [v[0]]*n k = math.ceil(s/n) print(v[0] - k)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n,s = map(int,input().split()) st = list(map(int,input().split())) a,b = sum(st),min(st) if a<s: print(-1) else: c = a-n*b if s<=c: print(b) else: #print(s-c) print(b-(s-c+n-1)//n)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
# *********************************************** # # achie27 # # *********************************************** def retarray(): return list(map(int, input().split())) import math n, s = retarray() a = retarray() min_keg = min(a) acc = 0 for x in a: acc += (x - min_keg) if acc >= s: print(min_keg) else: x = math.ceil((s-acc)/n) if x > min_keg: print(-1) else: print(min_keg-x)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
line1 = [int(x) for x in input().split()] line2 = [int(x) for x in input().split()] n = line1[0] v = line1[1] def least_amount(n, v, line2): total = sum(line2) amount = min((total - v)//n, min(line2)) return amount if amount >= 0 else -1 print(least_amount(n, v, line2))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n,s=map(int,input().split()) v=sorted(list(map(int,input().split()))) m=min(v) ss=sum(v) if(s>ss): print(-1) else: if(s<=ss-n*m): print(m) else: s=s-ss+n*m print(m-s//n-int(bool(s%n)))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
from os import path import sys,time # mod = int(1e9 + 7) # import re from math import ceil, floor,gcd,log,log2 ,factorial from collections import defaultdict ,Counter , OrderedDict , deque from itertools import combinations , groupby , zip_longest,permutations # from string import ascii_lowercase ,ascii_uppercase from bisect import * from functools import reduce from operator import mul maxx = float('inf') #----------------------------INPUT FUNCTIONS------------------------------------------# I = lambda :int(sys.stdin.buffer.readline()) tup= lambda : map(int , sys.stdin.buffer.readline().split()) lint = lambda :[int(x) for x in sys.stdin.buffer.readline().split()] S = lambda: sys.stdin.readline().strip('\n') grid = lambda r :[lint() for i in range(r)] stpr = lambda x : sys.stdout.write(f'{x}' + '\n') star = lambda x: print(' '.join(map(str, x))) localsys = 0 start_time = time.time() if (path.exists('input.txt')): sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w'); #left shift --- num*(2**k) --(k - shift) # input = sys.stdin.readline n ,s = tup() ls = lint() S = sum(ls) if s < s: print(-1) elif s ==S : print(0) else: ls.sort(reverse= True) x =0 for i in range(n-1): if x <s: p= min(s-x, ls[i]-ls[n-1]) x+=p ls[i] = ls[i]-p else: break s-=x if s == 0: print(ls[n-1]) else: print(max(-1,ls[n-1] - ceil(s/n))) if localsys: print("\n\nTime Elased :",time.time() - start_time,"seconds")
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.util.*; import java.math.*; public class Main { public static void main(String ards[]) { Scanner cin = new Scanner(System.in); long n = cin.nextLong(); long s = cin.nextLong(); long sum = 0, minn = 1000000000; for(int i = 0; i < n; i++) { long x = cin.nextLong(); minn = Math.min(minn, x); sum += x; } if(sum < s) System.out.println(-1); else System.out.println(Math.min(minn,(sum-s)/n)); } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
a,b=map(int,input().split()) z=list(map(int,input().split())) s=sum(z);r=min(z) if b>s:print(-1) elif s-r*a>=b:print(r) else: f=b-(s-r*a) print(max(0,(r-(f//a))-(0 if f%a==0 else 1)))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
N,S = map(int, input().split()) L = list(map(int, input().split())) x = 0 for i in range (N): x += L[i] - min(L) if x >= S: print(min(L)) elif S > sum(L): print('-1') else: y = S - x if y//N == y/N: k = y//N print(min(L) - k) else: k = y//N +1 print(min(L) - k)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.util.*; public class B { public static void main(String[]args){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(),s=sc.nextLong(); long sum=0,min=Long.MAX_VALUE; for(long i=0;i<n;i++){ long vi=sc.nextLong(); sum+=vi; if(vi<min) min=vi; } sc.close(); System.out.println(s>sum?-1:Math.min(min,(sum-s)/n)); } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#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; } } }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.IOException; import java.io.InputStreamReader; import java.io.BufferedReader; import java.util.*; import java.math.*; import java.io.*; public class hacker { /*Fatt Gyi Bhai*/ //Dekh le mera code public static boolean[] sieve(long n) { boolean[] prime = new boolean[(int)n+1]; Arrays.fill(prime,true); prime[0] = false; prime[1] = false; long m = (long)Math.sqrt(n); for(int i=2;i<=m;i++) { if(prime[i]) { for(int k=i*i;k<=n;k+=i) { prime[k] = false; } } } return prime; } static long GCD(long a,long 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); } static long CountCoPrimes(long n) { long res = n; for(int i=2;i*i<=n;i++) { if(n%i==0) { while(n%i==0) { n/=i; } res-=res/i; } } if(n>1) { res-=res/n; } return res; } //fastest way to find x**n static long modularExponentiation(long x,long n,long m) { long res = 1; while(n>0) { if(n%2==1) { res = (res*x)%m; } x =(x*x)%m; n/=2; } return res; } static long lcm(long a,long b) { return (a*b)/GCD(a,b); } static int pow(int a,int b) { int res = 1; while(b>0) { if((b&1)==1) { res *= a; } b >>= 1; a *=a; } return res; } static long modInverse(long A,long M) { return modularExponentiation(A,M-2,M); } static void reverse(int[] a,int start,int end) { while(start<end) { int temp = a[start]; a[start] = a[end]; a[end] = temp; start++; end--; } } static boolean prime(int n) { for(int i=2;i*i<=n;i++) { if(i%2==0 ||i%3==0) { return false; } } return true; } public static void main(String[] args) throws IOException { // in = new Scanner(new File("explicit.in")); //out = new PrintWriter("explicit.out"); new hacker().run(); } static int rev(int n) { int x=0; int num = 0; while(n>0) { x = n%10; num = num*10+x; n/=10; } return num; } static Scanner sc = new Scanner(System.in); static void run() throws IOException { long n = nl(); long s = nl(); long[] a = new long[(int)n+1]; long sum=0; long min =Long.MAX_VALUE; long max = Long.MIN_VALUE; for (int i=1;i<=n;++i ) { a[i] = nl(); sum+=a[i]; min = min(min,a[i]); max = max(a[i],max); } if(sum<s) { System.out.println(-1); return; } if(sum==s) { System.out.println(0); return; } else { System.out.println(min(min,(sum-s)/n)); } } static void print(long a) { System.out.println(a); } static void swap(char c,char p) { char t = c; c = p; p = t; } static long max(long n,long m) { return Math.max(n,m); } static long min(long n,long m) { return Math.min(n,m); } static double nd() throws IOException { return Double.parseDouble(sc.next()); } static int ni() throws IOException { return Integer.parseInt(sc.next()); } static long nl() throws IOException { return Long.parseLong(sc.next()); } static String si() throws IOException { return sc.next(); } static long abs(long n) { return Math.abs(n); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public boolean ready() throws IOException {return br.ready();} } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStreamReader; //import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; import java.util.StringTokenizer; import java.util.*; public class PJ { static HashMap<Long,Long> hs; public static void main(String[] args) throws Exception { StringTokenizer st ; //Scanner sc = new Scanner(System.in); boolean file = false; BufferedReader br =!file?new BufferedReader(new InputStreamReader(System.in)):new BufferedReader(new FileReader("leaves.in")); PrintWriter out = new PrintWriter(System.out); st = new StringTokenizer(br.readLine()); long n = Integer.parseInt(st.nextToken());long s = Long.parseLong(st.nextToken()); st = new StringTokenizer(br.readLine()); long[] arr = new long[(int)n]; long min = Long.MAX_VALUE; for(int i=0;i<n;i++) { arr[i] = Integer.parseInt(st.nextToken()); min=Math.min(min, arr[i]); } for(int i=0;i<n;i++) s -=arr[i]-min; long sum=(1l*n)*min; if (s<=0){ out.println(min); } else{ if (sum<s){ out.println(-1); } else { sum-=(s); long ans = sum/n; out.println(ans); } } out.flush(); out.close(); } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import math n,s = map(int,input().split()) l = list(map(int,input().split())) if sum(l) < s: print(-1) else: x = min(l) i = 0 while(i < len(l) and s > 0): s = s-(l[i]-x) i += 1 if s == 0 or s < 0: print(x) exit() if s > 0: print(x-math.ceil(s/n)) exit()
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = map(int, input().split()) num = list(map(int, input().split())) x = sum(num) if x < s: print(-1) else: k = min(num) for i in range(n): s -= abs(num[i] - k) num[i] = k if s <= 0: print(k) else: q = s // n k -= q if s % n == 0: print(k) else: print(k - 1)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import math n,s = [int(x) for x in input().split()] v = [int(x) for x in input().split()] if(sum(v) < s): print(-1) exit() m = min(v) for i in range(len(v)): s -= v[i] - m if(s <= 0): print(m) else: print(m - (s + n - 1) // n)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import os, sys, bisect from collections import defaultdict, Counter, deque; from functools import lru_cache #use @lru_cache(None) if os.path.exists('in.txt'): sys.stdin=open('in.txt','r') if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w') # input = lambda: sys.stdin.readline().strip() imap = lambda: map(int,input().split()); ilist = lambda: list(imap()) #------------------------------------------------------------------ #sys.setrecursionlimit(10**6) mod = int(1e9+7) n,s =imap() a = ilist() sm = sum(a)-n*min(a) if sm>=s: print(min(a)) else: rem = s-sm lvl = min(a)-(rem+n-1)//n if lvl<0: print(-1) else: print(lvl)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = map(int, input().split()) summ = 0 minn = 10000000000 for v in map(int, input().split()): minn = min(minn, v) summ += v if summ < s: print("-1") else: print(min(minn, (summ - s) // n))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Kvass { static BufferedReader _in = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer _stk; static String next() { try { while (_stk == null || !_stk.hasMoreTokens()) _stk = new StringTokenizer(_in.readLine()); return _stk.nextToken(); } catch(Exception ex) { throw new RuntimeException("Failed reading input", ex); } } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } public static void main(String [] args) throws IOException { N = nextInt(); S = nextLong(); long sum = 0; keg = new long[N]; long minkeg = (long)1e9; for(int i=0; i<N; i++) { keg[i] = nextLong(); sum += keg[i]; minkeg = Math.min(minkeg, keg[i]); } if(sum<S) { System.out.println(-1); return; } long res = solve(minkeg); System.out.println(res); } private static long solve(long minkeg) { long lo = 0, hi = minkeg+1; while(lo<hi) { long mid = lo +(hi-lo)/2; if(cantFill(mid)) { hi = mid; } else { lo = mid+1; } } if(!cantFill(lo)) { return minkeg; } return lo-1; } private static boolean cantFill(long val) { long sum = 0; for(long k : keg) { if(k>=val) { sum += k-val; } if(sum>=S) return false; } return true; } static int N; static long S; static long[] keg; }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.BufferedReader; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskF solver = new TaskF(); solver.solve(1, in, out); out.close(); } static class TaskF { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); long s = in.nextLong(); long k = s; long[] a = new long[n]; long m = -1; for (int i = 0; i < n; ++i) { a[i] = in.nextLong(); if(k > 0) { k -=a[i]; } if(m == -1 || m > a[i]) { m = a[i]; } } if(k > 0) { out.println(-1); return; } long c = 0; c = 0; for (int i = 0; i < n; ++i) { c += (a[i] - m); } if(c >= s) { out.println(m); return; } long r = s - c; long x = r/n; if(r%n == 0) { out.println(m - x); } else { out.println(m - x -1); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#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]; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
n,s=[int(x) for x in input().split()] b=[int(x) for x in input().split()] minb=min(b) if sum(b)-minb*len(b)>=s: print(minb) elif sum(b) - minb*len(b)<s: s-=(sum(b) - minb*len(b)) ot=minb-(s//len(b)) if s%len(b)!=0: ot-=1 if ot>=0: print(ot) else: print(-1)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = map(int, input().split()) ar = list(map(int, input().split())) m = min(ar) x = 0 for i in ar: x += i - m if x >= s: print(m) else: left = s - x print(max(m - ((left - 1) // n + 1), -1))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import java.util.*; import java.io.*; public class Solution { public static void main(String args[]) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] inp2 = br.readLine().trim().split("\\s"); String inp1[] = br.readLine().trim().split("\\s"); int n = Integer.parseInt(inp2[0]); long req = Long.parseLong(inp2[1]); long keg[] = new long[n]; long sum = 0; long min = Integer.MAX_VALUE; for(int i=0; i<n; i++) { keg[i] = Integer.parseInt(inp1[i]); sum += keg[i]; min = Math.min(min, keg[i]); } if(sum < req) { System.out.println(-1); } else { long over = 0; for(int i=0; i<n; i++) over += (keg[i] - min); if(over >= req) { System.out.println(min); } else { req = req - over; long toDel = 0; if(req % n == 0) toDel = req/n; else toDel = req/n + 1; System.out.println((min - toDel)); } } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
n,s=list(map(int,input().split())) a=list(map(int,input().split())) p=sum(a) m=min(a) if(s>p): print(-1) elif(p==s): print(0) elif(s<=p-(n*m)): print(m) else: s=s-(p-(n*m)) p=n*m p=p-s print(p//n)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
line = input() n, s = [int(x) for x in line.split()] line = input() vs = [int(x) for x in line.split()] sm = sum(vs) if sm < s: print(-1) else: mn = min(vs) tot = sum([x - mn for x in vs]) if tot < s: diff = s - tot mn -= int(diff/n) dv = 1 if diff % n > 0 else 0 mn -= dv print(mn)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import math n,s=map(int , input().split()) result=[int(i) for i in input().split()] result.sort(reverse=True) tot=sum(result) if tot<s: print(-1) elif tot==s: print(0) else: x=tot-(result[-1]*n) a=n*result[-1] if s<=x: print(result[-1]) else: p=s-x a=math.ceil(p/n) print(result[-1]-a)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import sys from math import ceil if __name__ == "__main__": n, s = [int(val) for val in input().split()] a = [int(val) for val in input().split()] total = sum(a) if(total < s): print("-1") else: summ = 0 smallest = min(a) for i in a: summ += abs(smallest - i) if(summ >= s): pass else: diff = s - summ pours = int(ceil(float(diff) / float(n))) smallest -= pours print(smallest)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
#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)); }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
#!/usr/bin/env python3 n, s = map(int, input().split()) l = list(map(int, input().split())) if sum(l) < s: print(-1) else: print(min((sum(l)-s)//n, min(l)))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n,s=map(int,raw_input().split()) l=list(map(int,raw_input().split())) u,a=sum(l),min(l) if u<s: print -1 else: v=u-s print min(a,v//n)
PYTHON
1084_B. Kvass and the Fair Nut
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.
2
8
#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; } } } } }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import math n,k=[int(x) for x in input().split()] arr=[int(x) for x in input().split()] total=sum(arr) if(total<k): print(-1) elif(total==k): print(0) else: smallest=min(arr) rem=total-n*smallest if(rem>=k): print(smallest) else: rem=k-rem print(smallest-(int)(math.ceil(rem/n)))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); while(sc.hasNext()) { long n = sc.nextLong(); long s = sc.nextLong(); long min = 999999999; long sum=0; for(int i=0;i<n;i++) { long t = sc.nextLong(); min = Math.min(t,min); sum+=t; } if(sum<s) { System.out.println(-1); }else { System.out.println(Math.min(min,(sum-s)/n)); } } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
n,s=map(int,input().split()) a=list(map(int,input().split())) m=min(a) l=0 if sum(a)<s: print(-1) if sum(a)>s: for i in range(n): l+=a[i]-m if l>=s: print(m) else: res=s-l b=res//n m-=b if res%n!=0: m-=1 print(m) if sum(a)==s: print(0)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import math n=input().split() a=input().split() for i in range(int(n[0])): a[i]=int(a[i]) a.sort() a=a[::-1] v=int(n[1]) f=0 mi=0 for j in range(int(n[0])): if a[-1]!=a[j]: v-=a[j]-a[-1] a[j]=a[-1] if v<=0: print(a[-1]-f) break if v>0: if v>int(n[0])*(a[0]-f): print(-1) else: print(a[-1]-math.ceil(v/int(n[0])))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.*; import java.util.*; import java.math.*; public class c2 { static Scanner sc; static PrintStream ps; public static void main(String [] args) { ps= System.out; sc= new Scanner(System.in); int n = sc.nextInt(); long s = sc.nextLong(); long sum = 0; long min = 1000000000; long [] ar = new long[n+1]; for(int i = 0; i < n; i++) { ar[i] = sc.nextLong(); sum+=ar[i]; min = min>ar[i]? ar[i]:min; } if(sum < s) ps.println(-1); else { long left = min*n; long taken = sum - left; if(s < taken) ps.println(min); else { s = s-taken; if(s %n == 0) { long t = s/n; //Arrays.fill(ar,min-t); ps.println(min-t); } else { //ps.println(mo+""+s); long mo = s%n; s = s-mo; long t = s/n; ps.println(min-t-1); } } } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = map(int, input().split()) u = list(map(int, input().split())) mu = min(u) su = sum(u) if su < s: print(-1) else: s -= (su - mu * n) if s <= 0: print(mu) else: k = s // n if s % n != 0: k += 1 print(mu - k)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.*; import java.util.*; public class Main { private static final int MAX = Integer.MAX_VALUE; private static final int MIN = Integer.MIN_VALUE; public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream); Scanner scanner = new Scanner(System.in); int n = in.nextInt(); long s = in.nextLong(); int [] a = new int[n]; long sum = 0; for (int i = 0; i < a.length; i++) { a[i] = in.nextInt(); sum+=a[i]; } if(sum < s) { out.println(-1); } else { int max = a[0]; for(int i : a) { max = Math.max(max,i); } int lo = 1; int hi = 1_000_000_000; while (lo<=hi) { int med = (lo+hi)/2; if (can(a,med,s)) { lo = med + 1; } else { hi = med - 1; } } out.println(hi); } out.flush(); } private static boolean can(int [] a, int min, long s) { long sum = 0; for (int i = 0; i < a.length; i++) { if(a[i] < min) return false; sum+=a[i]-min; } return sum>=s; } private static int binarySearch(int [] a, int min) { int lo = 0; int hi = a.length - 1; while(lo<=hi) { int med = lo+(hi-lo)/2; if(min > a[med]) { lo = med + 1; } else { hi = med - 1; } } return lo; } private static int [] freq(char [] c) { int [] f = new int[26]; for(char cc : c) { f[cc-'a']++; } return f; } private static void shuffle(int [] a) { for (int i = 0; i < a.length; i++) { int index = (int)(Math.random()*(i+1)); int temp = a[index]; a[index] = a[i]; a[i] = temp; } } private static int lowerBound(int [] a, int target) { int lo = 0; int hi = a.length - 1; while (lo<=hi) { int med = lo + (hi-lo)/2; if(target >= a[med]) { lo = med + 1; } else { hi = med - 1; } } return lo; } static int numberOfSubsequences(String a, String b) { int [] dp = new int[b.length()+1]; dp[0] = 1; for (int i = 0; i < a.length(); i++) { for (int j = b.length() - 1; j >=0;j--) { if(a.charAt(i) == b.charAt(j)) { dp[j+1]+=dp[j]; } } } return dp[dp.length - 1]; } static long count(String a, String b) { int m = a.length(); int n = b.length(); // Create a table to store // results of sub-problems long lookup[][] = new long[m + 1][n + 1]; // If first string is empty for (int i = 0; i <= n; ++i) lookup[0][i] = 0; // If second string is empty for (int i = 0; i <= m; ++i) lookup[i][0] = 1; // Fill lookup[][] in // bottom up manner for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { // If last characters are // same, we have two options - // 1. consider last characters // of both strings in solution // 2. ignore last character // of first string if (a.charAt(i - 1) == b.charAt(j - 1)) lookup[i][j] = lookup[i - 1][j - 1] + lookup[i - 1][j]; else // If last character are // different, ignore last // character of first string lookup[i][j] = lookup[i - 1][j]; } } return lookup[m][n]; } } class Point { private int x; private int y; public int getX() { return x; } public int getY() { return y; } public Point(int x,int y) { this.x = x; this.y = y; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Point point = (Point) o; return x == point.x && y == point.y; } @Override public int hashCode() { return Objects.hash(x, y); } } class InputReader extends BufferedReader { StringTokenizer tokenizer; public InputReader(InputStream inputStream) { super(new InputStreamReader(inputStream), 32768); } public InputReader(String filename) { super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename))); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(readLine()); } catch (IOException e) { throw new RuntimeException(); } } return tokenizer.nextToken(); } public Integer nextInt(){ return Integer.valueOf(next()); } public Long nextLong() { return Long.valueOf(next()); } public Double nextDouble() { return Double.valueOf(next()); } static class OutputWriter extends PrintWriter { public OutputWriter(OutputStream outputStream) { super(outputStream); } public OutputWriter(Writer writer) { super(writer); } public OutputWriter(String filename) throws FileNotFoundException { super(filename); } public void close() { super.close(); } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#Winners never quit, quiters never win............................................................................ from collections import deque as de import math from collections import Counter as cnt from functools import reduce from typing import MutableMapping from itertools import groupby as gb def factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) class My_stack(): def __init__(self): self.data = [] def my_push(self, x): return (self.data.append(x)) def my_pop(self): return (self.data.pop()) def my_peak(self): return (self.data[-1]) def my_contains(self, x): return (self.data.count(x)) def my_show_all(self): return (self.data) def isEmpty(self): return len(self.data)==0 arrStack = My_stack() def decimalToBinary(n): return bin(n).replace("0b", "") def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True def get_prime_factors(number): prime_factors = [] while number % 2 == 0: prime_factors.append(2) number = number / 2 for i in range(3, int(math.sqrt(number)) + 1, 2): while number % i == 0: prime_factors.append(int(i)) number = number / i if number > 2: prime_factors.append(int(number)) return prime_factors def get_frequency(list): dic={} for ele in list: if ele in dic: dic[ele] += 1 else: dic[ele] = 1 return dic def Log2(x): return (math.log10(x) / math.log10(2)); def isPowerOfTwo(n): return (math.ceil(Log2(n)) == math.floor(Log2(n))); #here we go...................... #Winners never quit, Quitters never win n,s=map(int,input().split()) v=sorted(list(map(int,input().split())),reverse=True) if sum(v) < s: print(-1) elif sum(v) == s: print(0) else: mn=min(v) ch=0 for i in range(n-1): s-=v[i]-mn if s<=0: ch=1 break if ch: print(mn) else: temp=math.ceil(s/n) print(mn-temp)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
from sys import stdin, stdout from math import * from heapq import * from collections import * def tryLeastkeg(mink): i=n-1 k=0 t=0 while(i>=0): if (v[i]>mink): t=t+(v[i]-mink) k=k+1 if (t>=s): return True i=i-1 return False def main(): global n,s,v,res n,s=[int(x) for x in stdin.readline().split()] v=[int(x) for x in stdin.readline().split()] v.sort() l=0 r=min(v) res=-1 while(l<=r): mid=floor((l+r)/2) if (tryLeastkeg(mid)==True): if (res<0): res=mid else: res=max(res,mid) l=mid+1 else: r=mid-1 stdout.write(str(res)) return 0 if __name__ == "__main__": main()
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class KvassAndFairNut { private static final FastReader in = new FastReader(); private static final PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { Solver sol = new Solver(); int tt = 1; sol.solve(tt); out.close(); } private static final class Solver { public void solve(int testCase) { int n = in.nextInt(); long s = Long.parseLong(in.next()); int[] a = new int[n]; long sum = 0L; int min = Integer.MAX_VALUE; for (int i = 0; i < n; ++i) { a[i] = in.nextInt(); sum += a[i]; min = Math.min(min, a[i]); } if (sum < s) out.println(-1); else { out.println(Math.min(min, (sum - s) / n)); } } } private static final class FastReader { private BufferedReader br; private StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in), 1 << 16); st = null; } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = map(int, raw_input().split()) v = map(int, raw_input().split()) tot = sum(v) if tot < s: print -1 else: lo = 0 hi = max(v) while lo +1 < hi: mid = (lo+hi)/2 #print "trying", mid, "hi", hi, "lo", lo amt = sum(map(lambda vi: max(0, vi-mid), v)) #print "amt", amt if amt < s: hi = mid else: lo = mid print min(min(v), lo)
PYTHON
1084_B. Kvass and the Fair Nut
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.
2
8
R = lambda: map(int,input().split()) n,m = R() L = list(R()) if sum(L) < m: print(-1) else: mi = min(L) for i in range(n): if m > 0: m -= (L[i]-mi) else: break if m <= 0: print(mi) else: print(mi-((m+n-1)//n))
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = map(int, raw_input().split()) v = sorted(map(int, raw_input().split())) total = sum(v) if total < s: print '-1' else: mx = min(v) r = total - mx * n if s <= r: print mx else: ex = (s-r+n-1) // n print mx - ex
PYTHON
1084_B. Kvass and the Fair Nut
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.
2
8
n, s = map(int, input().split()) v = list(map(int, input().split())) v.sort(key=lambda x:-x) sm = 0 out = v[-1] for i in range(n - 1): sm += v[i] - v[-1] out += v[i] if out < s: print(-1) exit(0) if sm >= s: print(v[-1]) exit(0) print(v[-1] - (s - sm - 1) // n - 1)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; public class _1084B { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(in, out); out.close(); } private static class Solver { private void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); long s = in.nextLong(); long total = 0; long minim = 1000000000L; for (int i = 0; i < n; i++) { long tmp = in.nextLong(); total += tmp; minim = Math.min(tmp, minim); } if (total < s) { out.println(-1); } else { out.println(binarySearch(0, minim, n, total - s)); } } private long binarySearch(long l, long r, int n, long maks) { if (l == r) return l; long m = (l + r + 1) / 2; if (m * n <= maks) { return binarySearch(m, r, n, maks); } else { return binarySearch(l, m - 1, n, maks); } } } private static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; private InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } private int nextInt() { return Integer.parseInt(next()); } private long nextLong() { return Long.parseLong(next()); } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } public static void main(String args[]) { FastReader s=new FastReader(); int n=s.nextInt(); long l=s.nextLong(); long sum=0l; ArrayList<Integer> al=new ArrayList<Integer>(); while(n-->0) { int temp=s.nextInt(); al.add(temp); sum+=(long)temp; } if(l>sum) { System.out.println("-1"); System.exit(0); } Collections.sort(al); int min=al.get(0); n=al.size(); for(int i=1;i<n;i++) { int temp=al.get(i)-min; l-=(long)temp; } while(l>0l) { l-=n; min--; } System.out.println(min); } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
// 526 - Dev 2 - B import java.io.IOException; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static long calculate() { int n = sc.nextInt(); long s = sc.nextLong(); long v[] = new long[n]; long sum = 0,min = Integer.MAX_VALUE,delta = 0,result; for(int i = 0; i < n; i++){ v[i] = sc.nextLong(); sum += v[i]; min = Math.min(min, v[i]); } if(sum < s) return -1; for(int i = 0; i < n; i++){ delta += (v[i] - min); } if(delta >= s) return min; long temp = (s - delta) / n; if( (s - delta) % n != 0) temp += 1; min -= temp; return min; } public static void main(String args[]) throws IOException { long result = calculate(); System.out.println(result); } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
n ,m = [int(i) for i in input().split()] v = [int(i) for i in input().split()] if sum(v) < m: print(-1) else: st = 0 en = min(v)+1 while(st < en): mid = (st+en)//2 cnt = 0 for i in v: cnt += i - mid if(cnt >= m): st = mid+1 else: en = mid print(st-1)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
def inint(): return int(input()) def inlist(): return list(map(int,input().split())) def main(): n,s=inlist() a=inlist() sm=sum(a) if s>sm:print(-1);return lst=min(a) sm1=sm-lst*n if s<sm1:print(lst) else: from math import ceil print(lst-ceil((s-sm1)/n)) if __name__ == "__main__": #import profile #profile.run("main()") main()
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
n,s=map(int,input().split()) a=list(map(int,input().split())) before,after,mini=0,0,10**12 for i in range(n): before+=a[i] mini=min(mini,a[i]) after=before-s if after<0: print("-1") exit() each=int(after/n) if mini<each: print(mini) else : print(each)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import math n, s = map(int, input().split()) kegs = [int(k) for k in input().split()] if s > sum(kegs): print(-1) exit() opsleft = s minimum = min(kegs) amtleft = 0 for keg in kegs: amtleft += keg-minimum if s <= amtleft: print(minimum) else: res = minimum - math.ceil((s - amtleft) / n) print(res)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
#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; }
CPP
1084_B. Kvass and the Fair Nut
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.
2
8
from math import ceil n,s=list(map(int,input().split())) liter_li=list(map(int,input().split())) if sum(liter_li)<s: print(-1) else: if s<=sum(liter_li)-min(liter_li)*n: print(min(liter_li)) else: s-=sum(liter_li)-min(liter_li)*n a=int(ceil(s/n)) print(min(liter_li)-a)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(1, in, out); out.close(); } static class P implements Comparable<P> { int a; int b; @Override public int compareTo(P arg0) { if(arg0.a > this.a) return 1; else return -1; } } static class Task { static final int maxl = 200020; public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); long s = in.nextLong(); int a[] = new int[n]; for(int i=0;i<n;i++) { a[i] = in.nextInt(); } Arrays.sort(a, 0, n); long ans = 0; for(int i=1;i<n;i++) { ans+=a[i] - a[0]; } if(ans>=s) out.println(a[0]); else { s-=ans; if(s>(long) n*a[0]) { out.println(-1); } else { long temp = s%n; if(temp == 0) out.println(a[0]-s/n); else { out.println(a[0]-s/n-1); } } } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
n, S = [int(x) for x in input().split()] A = [int(x) for x in input().split()] def ans(): global S to_min = sum(A) - n*min(A) S -= to_min if S <= 0: return min(A) if n*min(A) < S: return -1 return (n*min(A) - S) // n print(ans())
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import java.util.Arrays; import java.util.Scanner; public class B526 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner obj=new Scanner(System.in); long n=obj.nextInt(); long s=obj.nextLong(); long arr[]=new long[(int) n]; long su=0; for(long i=0;i<n;i++) { arr[(int) i]=obj.nextLong(); su+=arr[(int) i]; } Arrays.parallelSort(arr); long ele=arr[0]; long sum=0; for(long i=1;i<n;i++) { sum+=arr[(int) i]-ele; } if(su<s) { System.out.println("-1"); } else if(sum>=s) { System.out.println(arr[0]); } else { double diff=s-sum; double b=(diff/n); long ans=(long)Math.ceil(b); //System.out.println(ans); System.out.println(arr[0]-ans); } } }
JAVA
1084_B. Kvass and the Fair Nut
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.
2
8
R=lambda:map(int,raw_input().split()) n,m=R() a=sorted(R()) s=sum(a) if s<m: print -1 elif s-a[0]*n<m: print (s-m)/n else: print a[0]
PYTHON
1084_B. Kvass and the Fair Nut
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.
2
8
import math n, s = map(int, input().split()) x = list(map(int, input().split())) cur_min = min(x) sum_x = sum(x) ans = 0 if sum_x < s: print(-1) else: ans = sum_x - n * cur_min if ans < s: cur_min -= math.ceil((s - ans) / n) print(cur_min)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
import math n,k = map(int, input().strip().split(' ')) lst = list(map(int, input().strip().split(' '))) s=sum(lst) if s<k: print(-1) else: c=0 m=min(lst) for i in range(n): c+=lst[i]-m lst[i]=m if c>=k: print(m) else: k-=c c1=k%n if c1==0: print(m-(k//n)) else: print(m-(k//n)-1)
PYTHON3
1084_B. Kvass and the Fair Nut
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.
2
8
from sys import stdin, stdout input = stdin.readline rstr = lambda: input().strip() rstrs = lambda: [str(x) for x in input().split()] rstr_2d = lambda n: [rstr() for _ in range(n)] rint = lambda: int(input()) rints = lambda: [int(x) for x in input().split()] rint_2d = lambda n: [rint() for _ in range(n)] rints_2d = lambda n: [rints() for _ in range(n)] n, s = rints() a = rints() if sum(a) < s: print(-1) else: mi, diff = min(a), 0 for i in a: diff += i - mi s -= diff if s <= 0: print(mi) else: print((mi * n - s) // n)
PYTHON3