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
/* import java.util.Arrays; import java.util.Scanner; public class KvassAndTheFairNut { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); long s = in.nextLong(); long[] kegs = new long[n]; long sum = 0; for (int i = 0; i < n; i++) { kegs[i] = in.nextLong(); sum+=kegs[i]; } if (sum < s) { System.out.println(-1); return; } Arrays.sort(kegs); long Min = kegs[0]; long cur = 0; for (int i = n - 1; i >= 0; i--) { if (kegs[i] == Min) { break; } cur += kegs[i] - Min; kegs[i] = Min; if (cur >= s) { System.out.println(Min); return; } } while (kegs[0] > 0) { cur += n; kegs[0]--; if (cur >= s) { System.out.println(kegs[0]); return; } } System.out.println(-1); } } */ import java.util.*; import java.io.*; public class KvassAndTheFairNut { public static void main(String args[]) { FastReader ss = new FastReader(); int n = ss.nextInt(); long s = ss.nextLong(); long sum = 0l; int[] kegs = new int[n]; while (n-- > 0) { int temp = ss.nextInt(); kegs[n] = temp; sum += (long) temp; } if (s > sum) { System.out.println("-1"); System.exit(0); } Arrays.sort(kegs); int min = kegs[0]; n = kegs.length; for (int i = 1; i < n; i++) { int temp = kegs[i] - min; s -= (long) temp; } while (s > 0l && min > 0) { s -= n; min--; } System.out.println(min); } 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()); } } }
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
#_________________ Mukul Mohan Varshney _______________# #Template import sys import os import math import copy from math import gcd from bisect import bisect from io import BytesIO, IOBase from math import sqrt,floor,factorial,gcd,log,ceil from collections import deque,Counter,defaultdict from itertools import permutations, combinations #define function def Int(): return int(sys.stdin.readline()) def Mint(): return map(int,sys.stdin.readline().split()) def Lstr(): return list(sys.stdin.readline().strip()) def Str(): return sys.stdin.readline().strip() def Mstr(): return map(str,sys.stdin.readline().strip().split()) def List(): return list(map(int,sys.stdin.readline().split())) def Hash(): return dict() def Mod(): return 1000000007 def Ncr(n,r,p): return ((fact[n])*((ifact[r]*ifact[n-r])%p))%p def Most_frequent(list): return max(set(list), key = list.count) def Mat2x2(n): return [List() for _ in range(n)] def Prime_factors(n): i = 2 factors = set() while i * i <= n: if n % i: i += 1 else: n //= i factors.add(i) if n > 1: factors.add(n) print(factors) if len(factors)==2: return True else: return False def Divisors(n) : l = [] for i in range(1, int(math.sqrt(n) + 1)) : if (n % i == 0) : if (n // i == i) : l.append(i) else : l.append(i) l.append(n//i) return l def Sieve(n): prime=[True for i in range(n+1)] lst=[] p=2 while p*p<=n: if prime[p]: for i in range(p*p,n+1,p): prime[i]=False p=p+1 for i in range(2,n+1): if prime[i]: lst.append(i) return lst def minimum_integer_not_in_list(a): b=max(a) if(b<1): return 1 A=set(a) B=set(range(1,b+1)) D=B-A if len(D)==0: return b+1 else: return min(D) # Driver Code def solution(): n,s=Mint() a=List() if(sum(a)<s): print(-1) else: print(min(min(a),(sum(a)-s)//n)) #Call the solve function if __name__ == "__main__": solution()
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; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; ll s; cin >> n >> s; vector<int> a(n); ll sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } if (sum < s) { cout << -1 << '\n'; return 0; } sort(a.begin(), a.end()); int lo = 0, hi = a[0] + 1; while (lo + 1 < hi) { int mid = (lo + hi) / 2; ll t = 0; for (int i = 0; i < n; i++) { t += max(0, a[i] - mid); } if (t >= s) { lo = mid; } else { hi = mid; } } cout << lo << '\n'; }
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
first = input() first = first.split(" ") second = input() second = second.split(" ") n= int(first[0]) s = int(first[1]) v = [] # people_ = people_.split(" ") for p in second: v.append(int(p)) if sum(v) < s: print(-1) elif sum(v) == s: print(0) else: min_volume = min(v) sum = 0 v_ = [] for each in v: sum += each - min_volume v_.append(min_volume) if sum>=s: print(min_volume) else: s = s-sum volume_r = s/n if s%n !=0: volume_r +=1 print(min_volume-int(volume_r))
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 problem2 { 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
import java.io.*; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; import java.util.StringTokenizer; public class d { public static void print(String str,long val){ System.out.println(str+" "+val); } public long gcd(long a, long b) { if (b==0L) return a; return gcd(b,a%b); } public static void debug(long[][] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.println(Arrays.toString(arr[i])); } } public static void debug(int[][] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.println(Arrays.toString(arr[i])); } } public static void debug(String[] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.println(arr[i]); } } public static void print(int[] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.print(arr[i]+" "); } System.out.print('\n'); } public static void print(Object[] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.print(arr[i]+" "); } System.out.print('\n'); } public static void print(String[] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.print(arr[i]+" "); } System.out.print('\n'); } public static void print(long[] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.print(arr[i]+" "); } System.out.print('\n'); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String path) throws FileNotFoundException { br = new BufferedReader(new FileReader(path)); } 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; } } static void sort(long[] arr){ Long[] temp = new Long[arr.length]; for(int i=0;i<arr.length;i++){ temp[i] = arr[i]; } Arrays.sort(temp); for(int i=0;i<arr.length;i++){ arr[i] = temp[i]; } } public static void main(String[] args) { FastReader s=new FastReader(); int n = s.nextInt(); long vol = s.nextLong(); long[] arr = new long[n]; long sum =0; for(int i=0;i<n;i++){ arr[i] = s.nextInt(); sum+=arr[i]; } if(sum<vol){ System.out.println(-1); return; } long start = 0; long end = (long)(1e9); while (end>start+1){ long mid = (end+start)/2; if(search(mid,arr,vol)){ start =mid; } else { end = mid-1; } } if(search(end,arr,vol)){ System.out.println(end); return; } System.out.println(start); } static boolean search(long k,long[] arr,long vol){ long sum =0; for(int i=0;i<arr.length;i++){ if(arr[i]<k){ return false; } sum+=(arr[i]-k)*1l; } return (sum>=vol); } // OutputStream out = new BufferedOutputStream( System.out ); // for(int i=1;i<n;i++){ // out.write((arr[i]+" ").getBytes()); // } // out.flush(); // long start_time = System.currentTimeMillis(); // long end_time = System.currentTimeMillis(); // System.out.println((end_time - start_time) + "ms"); }
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() { int n; long long int s, sum = 0; cin >> n >> s; long long int* v = new long long int[n]; for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } if (s > sum) cout << -1 << endl; else { sort(v, v + n); if (s < (sum - v[0] * n)) cout << v[0] << endl; else { s -= sum - v[0] * n; if (s % n == 0) cout << v[0] - s / n << endl; else cout << v[0] - (s / n) - 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 math n,q=map(int,input().split()) h=list(map(int,input().split())) t=0 for i in range (n): t+=h[i] if t<q: print(-1) exit() low=min(h) for i in range (n): q-=(h[i]-low) if q<=0: print(low) exit() low-=math.ceil(q/n) print(low)
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 Kvass526B { public static void main(String[] args) { Scanner s = new Scanner(System.in); int kegs = s.nextInt(); long glass = s.nextLong(); long sum =0l; int arr[] = new int[kegs]; for(int i =0;i<kegs;i++) { arr[i] = s.nextInt(); sum+=arr[i]; } if(sum<glass) { System.out.println(-1); return; } Arrays.sort(arr); long filled = 0l; int min = arr[0]; for(int i = arr.length-1;i>=0;i--) { if(arr[i]!=min) { filled+=arr[i]-min; arr[i] = min; } if(filled>=glass) break; } // for(int o:arr) { // System.out.print(o+" "); // } // System.out.println(); // System.out.println("Filled :"+filled); if(filled>=glass) { System.out.println(min); return; } long remaining = glass-filled; //System.out.println("Remaining : "+remaining); sum = 0l; for(int i=0;i<arr.length;i++) sum+=arr[i]; long ans = (sum-remaining)/arr.length; System.out.println(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
import math from decimal import Decimal import heapq def na(): n = int(input()) b = [int(x) for x in input().split()] return n,b def nab(): n = int(input()) b = [int(x) for x in input().split()] c = [int(x) for x in input().split()] return n,b,c def dv(): n, m = map(int, input().split()) return n,m def dva(): n, m = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] return n,m,b def eratosthenes(n): sieve = list(range(n + 1)) for i in sieve: if i > 1: for j in range(i + i, len(sieve), i): sieve[j] = 0 return sorted(set(sieve)) def nm(): n = int(input()) b = [int(x) for x in input().split()] m = int(input()) c = [int(x) for x in input().split()] return n,b,m,c def dvs(): n = int(input()) m = int(input()) return n, m n,s = map(int, input().split()) a = list(map(int, input().split())) if sum(a) < s: print(-1) exit() d = min(a) tc = 0 for i in a: tc += i - d if tc >= s: print(d) else: tc = s - tc if tc % n == 0: print(d - tc // n) else: print(d - tc //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.util.StringTokenizer; public class Q2 { public static void main(String[] args) throws IOException{ Reader.init(System.in); int n = Reader.nextInt(); Long s = Reader.nextlong(); int[] values = new int[n]; int place = 0; for (int i=0;i<n;i++) { values[i] = Reader.nextInt(); if (values[i]<values[place]) { place = i; } } Long diff = (long) 0; for (int i=0;i<n;i++) { diff += values[i] - values[place]; } if (diff >= s) { System.out.println(values[place]); } else { s = s - diff; long hey = (long) n*values[place]; if (hey < s) { System.out.println(-1); } else { if (s%n==0) System.out.println(values[place] - (s/n)); else { System.out.println(values[place] - (s/n + 1)); } } } } } class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } static long nextlong() throws IOException { 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class gr1 { static class InputReader { public BufferedReader br; public StringTokenizer token; public InputReader(InputStream stream) { br=new BufferedReader(new InputStreamReader(stream),32768); token=null; } public String next() { while(token==null || !token.hasMoreTokens()) { try { token=new StringTokenizer(br.readLine()); } catch(IOException e) { throw new RuntimeException(e); } } return token.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } static class card{ long a; int cnt; int i; public card(long a,int cnt,int i) { this.a=a; this.cnt=cnt; this.i=i; } } static class ascend implements Comparator<pair> { public int compare(pair o1,pair o2) { if(o1.b!=o2.b) return (int)(o1.b-o2.b); else return (int)(o1.a-o2.a); } } /*static class descend implements Comparator<pair> { public int compare(pair o1,pair o2) { if(o1.a!=o2.a){ return (o1.a-o2.a)*-1; } else { return (o1.b-o2.b); } } }*/ static class extra { static void shuffle(long a[]) { List<Long> l=new ArrayList<>(); for(int i=0;i<a.length;i++) l.add(a[i]); Collections.shuffle(l); for(int i=0;i<a.length;i++) a[i]=l.get(i); } static long gcd(long a,long b) { if(b==0) return a; else return gcd(b,a%b); } static boolean valid(int i,int j,int r,int c) { if(i>=0 && i<r && j>=0 && j<c) return true; else return false; } static boolean v[]=new boolean[100001]; static List<Integer> l=new ArrayList<>(); static int t; static void seive() { for(int i=2;i<100001;i++) { if(!v[i]) { t++; l.add(i); for(int j=2*i;j<100001;j+=i) v[j]=true; } } } static int binary(pair a[],int val,int n) { int mid=0,l=0,r=n-1,ans=0; while(l<=r) { mid=(l+r)>>1; if(a[mid].a==val) { r=mid-1; ans=mid; } else if(a[mid].a>val) r=mid-1; else { l=mid+1; ans=l; } } return (ans); } } static class pair{ long a; int b; public pair(long a,int n) { this.a=a; this.b=n; } } static InputReader sc=new InputReader(System.in); static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { solver s=new solver(); int t=1; while(t>0) { s.solve(); t--; } } static class solver { void solve() { int n=sc.nextInt(); long s=sc.nextLong(); long v[]=new long[n]; long min=Long.MAX_VALUE; long sum=0; for(int i=0;i<n;i++) { v[i]=sc.nextLong(); sum+=v[i]; if(v[i]<min) min=v[i]; } if(s>sum) System.out.println(-1); else { new extra().shuffle(v); Arrays.sort(v); for(int i=n-1;i>=1;i--) { s-=Math.min(v[i]-min,s); if(s==0) { System.out.println(min); System.exit(0); } } min-=(s/n)+((s%n==0)?0:1); 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
x,s=list(map(int,input().split())) l=list(map(int,input().split())) sum=0 for i in l: sum+=i if sum<s: print(-1) elif sum==s: print(0) else: k=sum-len(l)*min(l) if k>=s: print(min(l)) else: sum-=k s-=k ans=s//len(l) if s%len(l)!=0: ans+=1 print(min(l)-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
# -*- coding: utf-8 -*- """ Created on Sat Dec 15 09:06:15 2018 @author: Arsanuos """ def solve(): rd = lambda: list(map(int, input().split())) n, s = rd() arr = rd() k = sum(arr) if s > k: print(-1) return if s == k: print(0) return arr.sort(reverse=True) mi = arr[-1] tmp = 0 for item in arr: tmp += (item - mi) if tmp >= s: print(mi) else: tmp = s - tmp l = len(arr) mi -= int(tmp/l) tmp -= int(tmp/l) * l if tmp > 0 and tmp % l != 0: mi -= 1 if mi >= 0: print(mi) else: print(-1) solve()
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
def ifPoss(arr,v,h): tot = 0 for i in arr: tot += (i-h) return tot>=v def prog(): n,v = map(int,input().split()) arr = [int(x) for x in input().split()] minLev = -1 l,h = 0,min(arr) while(l<=h): m = int((l+h)/2) if(ifPoss(arr,v,m)): minLev = max(minLev,m) l = m+1 else: h = m-1 return minLev print(prog())
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 MAXN = 1e6 + 5; const long long INF = 1e18; const int M = 1e9 + 7; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << '\n'; err(++it, args...); } int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; int FX[] = {-2, -2, -1, -1, 1, 1, 2, 2}; int FY[] = {-1, 1, -2, 2, -2, 2, -1, 1}; long long n, m, l, r, d, a, b, k, u, p = -1, q, x, y, z, mn, mx, rem, ans, res = 0, c = 0; long long aa[2000]; long long ch(long long NN) { long long sm = 0; for (long long i = 0; i < n; i++) { if (aa[i] < NN) return 0; else sm += aa[i] - NN; } if (sm >= b) return sm; else return 0; } void _CODE() { cin >> n >> b; for (long long i = 0; i < n; i++) cin >> aa[i]; p = -1; l = 0; r = 1e9; while (l <= r) { m = (l + r) >> 1ll; if (ch(m)) l = m + 1, p = m; else r = m - 1; } cout << p; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; _CODE(); }
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
R = lambda: map(int, input().split()) n, s = R() v = [*R()] print(max(-1, min((sum(v) - s) // n, *v)))
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.awt.geom.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] args) throws Exception { long startTime = System.nanoTime(); int n = in.nextInt(); long s = in.nextLong(); long [] data = new long[n]; for(int i=0;i<n;i++) data[i] = in.nextLong(); if(n==1){ if(data[0]>=s){ out.println((data[0]-s)); exit(0); }else{ out.println(-1); exit(0); } } Arrays.sort(data); long covered = process(data); if(s<=covered){ out.println(data[0]); exit(0); }else{ long pending = s-covered; if(pending > data[0]*n) { out.println(-1); exit(0); } else{ long temp = (long)Math.ceil((pending+0.0)/n); out.println((data[0]-temp)); exit(0); } } long endTime = System.nanoTime(); err.println("Execution Time : +" + (endTime-startTime)/1000000 + " ms"); exit(0); } static long process(long [] data){ long min = data[0]; long res = 0; for(int i=1;i<data.length;i++){ if(data[i]>min){ res += (data[i]-min); data[i] = min; } } return res; } 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()); } public double nextDouble(){ return Double.parseDouble(next()); } } static void exit(int a) { out.close(); err.close(); System.exit(a); } static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static OutputStream errStream = System.err; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); static PrintWriter err = new PrintWriter(errStream); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); }
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.util.*; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.math.BigInteger; import java.util.Scanner; import java.util.StringTokenizer; public class temp { boolean possible(int v[],int min,long s) { for(int i=0;i<v.length;i++) { if(s==0) { if(v[i] < min) return false; } else { if(v[i] >= min) { if(s >= (v[i]-min)) s-=(v[i]-min); else s = 0; } else return false; } } return s==0 ? true:false; } void solve() throws IOException { FastReader sc = new FastReader(); int n = sc.nextInt(); long s = sc.nextLong(); int v[] = new int[n]; int l = 0,r = -1; for(int i=0;i<n;i++) { v[i] = sc.nextInt(); r = Math.max(r, v[i]); } int ans = -1; while(l<=r) { int mid = (l+r)/2; if(possible(v,mid,s)) { ans = mid; l = mid+1; } else r = mid-1; } System.out.println(ans); } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub new temp().solve(); } 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
import math n, s = (int(s2) for s2 in input().split(' ')) kegs = [int(s2) for s2 in input().split(' ')] min_keg = min(kegs) overflow = sum(keg - min_keg for keg in kegs) if s <= overflow: print(min_keg) else: remaining = s - overflow n = int(math.ceil(remaining / len(kegs))) if n > min_keg: print(-1) else: print(min_keg - 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()) lis=list(map(int,input().split())) if s>sum(lis): print(-1) exit() lis.sort(reverse=True) i=0 while i<n and s>0: if s<(lis[i]-lis[-1]): print(lis[-1]) exit() s-=(lis[i]-lis[-1]) lis[i]=lis[-1] i+=1 if s==0: print(lis[-1]) elif s%n==0: print(lis[-1]-s//n) else: print(lis[-1]-s//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.util.*; import java.io.*; public class Main{ public static long primeFactors(long n) { // Print the number of 2s that divide n while (n%2 == 0) { return 2; } // n must be odd at this point. So we can skip // one element (Note i = i +2) for (long i = 3; i <= Math.sqrt(n); i = i+2) { // While i divides n, print i and divide n while (n%i == 0) { return i; } } // This condition is to handle the case when n // is a prime number greater than 2 if (n > 2) return n; return 0; } public static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader inp = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(inp, out); out.close(); } static class Solver { public boolean possible(long x,long arr[],long s) { long sum=0; for(int i=0;i<arr.length;i++) { if(arr[i]-x<0) return false; sum+=arr[i]-x; } if(sum>=s) return true; return false; } private void solve(InputReader inp, PrintWriter out1) { int n = inp.nextInt(); long s = inp.nextLong(); long arr[] = new long[n]; long sum=0; for(int i=0;i<n;i++) { arr[i] = inp.nextLong(); sum+=arr[i]; } if(sum<s) { out1.println(-1); return; } Arrays.sort(arr); long left =0; long right = arr[n-1]+5; long ans =0; while(left<=right) { long mid = (left+right)/2; // out1.println("mid "+mid); if(possible(mid,arr,s)) { left = mid+1; ans = mid; } else { right=mid-1; } } out1.println(ans); } } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } 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()); } } } class ele{ long value; long i; boolean flag; public ele(long value,long i) { this.value = value; this.i=i; this.flag = false; } }
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.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * Created by Mach on 10.12.2018. */ public class round526a { public static void main(String[] args) { Reader526a r=new Reader526a(); r.init(System.in); int n=r.nextInt(); long s=r.nextLong(); int a[]=new int[n]; int min=Integer.MAX_VALUE; long sum=0; for(int i=0; i<n; i++) { a[i]=r.nextInt(); if (a[i]<min) min=a[i]; sum=sum+a[i]; } long res=-1; if (s<=(sum-(long)min*n)) {System.out.println(min); return;} if (s>(sum)) {System.out.println(res); return;} res=(sum-s)/(long)n; System.out.println(res); // 980'103'855'476 } } class Reader526a { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() /* throws IOException */ { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary try { tokenizer = new StringTokenizer( reader.readLine()); } catch(Exception e) {e.printStackTrace();} } return tokenizer.nextToken(); } static int nextInt() { return Integer.parseInt( next() ); } static long nextLong(){ return Long.parseLong(next());} static double nextDouble() { return Double.parseDouble( 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> long long int power(long long int x, long long int b) { long long int p = 1; while (b > 0) { if (b & 1) { p = p * x; p %= 1000000007; } b >>= 1; x *= x; x %= 1000000007; } return p % 1000000007; } using namespace std; struct lex_compare { bool operator()( const pair<long long int, pair<long long int, long long int> > p1, const pair<long long int, pair<long long int, long long int> > p2) { return (p1.first == p2.first) ? p1.second.first < p2.second.first : p1.first > p2.first; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long int n, s; cin >> n >> s; long long int arr[n]; long long int sum = 0; long long int mint = INT_MAX; for (long long int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; mint = min(arr[i], mint); } if (sum < s) { cout << -1 << "\n"; return 0; } else if (sum == s) { cout << 0 << "\n"; return 0; } long long int sum2 = sum - n * mint; if (sum2 >= s) { cout << mint << "\n"; } else { s -= sum2; cout << (n * mint - s) / n << "\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
#include <bits/stdc++.h> using namespace std; int main() { long long n, s, v[1010], t = 0; cin >> n >> s; for (long long i = 0; i < n; ++i) { cin >> v[i]; t += v[i]; } if (t < s) { puts("-1"); return 0; } sort(v, v + n); t = 0; for (int i = 1; i < n; ++i) { t += v[i] - v[0]; } if (t >= s) { cout << v[0] << endl; return 0; } long long k = (s - t) / n; t += k * n; if (t < s) ++k; cout << v[0] - k << 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
// package PCS; // Working program with FastReader import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Kvass { 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; } } public static void main(String[] args) { FastReader reader = new FastReader(); int n = reader.nextInt(); long glass = reader.nextLong(); long min = Long.MAX_VALUE; long sum = 0; long poured = 0; long[] kvass = new long[n]; for (int i=0;i<n;i++) { long next = reader.nextLong(); sum += next; if (next < min) min = next; kvass[i] = next; } if (sum < glass) { System.out.println("-1"); return; } // long inEach = (sum - glass) / n; // System.out.println(inEach); for (int i=0;i<n;i++) { poured += kvass[i] - min; kvass[i] = min; } if (poured >= glass) { System.out.println(min); } else { long low = 0; long high = min; long mid = 0; while (low < high) { mid = (low + high) /2; // System.out.println(low + "\t" + mid + "\t" + high); if (poured + (min-mid) * n >= glass) { low = mid; if (poured + (min-mid-1) * n < glass) { break; } } else { high = mid; } } System.out.println(mid); } } }
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
# -*- coding: utf-8 -*- N, S = map(int, input().split()) aN = list(map(int, input().split())) if (sum(aN) - S) / N < 0: print(-1) else: print(min((sum(aN) - S) // N, min(aN)))
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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ 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); BKvassAndTheFairNut solver = new BKvassAndTheFairNut(); solver.solve(1, in, out); out.close(); } static class BKvassAndTheFairNut { long[] v; long s; public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); s = in.nextLong(); v = in.nextLongArray(n); long sum = 0; long min = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { sum += v[i]; min = Math.min(v[i], min); } if (sum < s) { out.println(-1); } else { long l = -1; long r = min + 1; while (r - l > 1) { long mid = (l + r) / 2; if (f(mid)) l = mid; else r = mid; } out.println(l); } } boolean f(long check) { long fill = 0; for (int i = 0; i < v.length; i++) { fill += (v[i] - check); } if (fill >= s) return true; return false; } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; 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 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; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public long[] nextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) array[i] = nextLong(); return array; } } }
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 a[5000]; int main() { int n; long long m; cin >> n >> m; long long sum = 0ll; for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; sort(a + 1, a + 1 + n); long long fuck = 0ll; for (int i = 2; i <= n; i++) fuck += a[i] - a[1]; m -= fuck; if (m <= 0) return cout << a[1], 0; int flag = 0; if (m % n != 0) flag = 1; m /= n; m += flag; cout << max(-1ll, a[1] - m); 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 main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, s; cin >> n >> s; vector<long long> v(n); long long sum = 0, minimum = 1e9; for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; if (v[i] < minimum) minimum = v[i]; } sum -= s; if (sum < 0) cout << -1 << endl; else cout << min(minimum, sum / 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, s = map(int, input().split()) k = list(map(int, input().split())) sumk = sum(k) mink = min(k) if sumk < s: print(-1) exit() if sumk-n*mink >= s: print(mink) else: s -= sumk-n*mink if s%n == 0: print(mink-s//n) else: print(mink-s//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
n,s=map(int,input().split()) l=list(map(int,input().split())) sa=sum(l) sa-=s if sa<0: print(-1) else: sa//=n if min(l)<sa: print(min(l)) else: print(sa)
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> const char dl = '\n'; const long double eps = 0.00000001; const long long MOD = 1e9 + 7; const double PI = 3.141592653589793238463; using namespace std; void debug() { cout << endl; } template <typename H, typename... T> void debug(H p, T... t) { std::cout << p << " "; debug(t...); } long long ans; int n, m, k; long long second, sum; int main() { fflush(stdin); cout << fixed, cout.precision(18); ios_base::sync_with_stdio(false); cin.tie(NULL); int i, j; cin >> n >> second; long long a[n]; for (i = 0; i < n; ++i) cin >> a[i], sum += a[i]; if (sum < second) return cout << -1, 0; long long up = 0; sort(a, a + n); long long mi = a[0]; for (i = 0; i < n; ++i) up += (a[i] - mi); second -= up; if (second <= 0) return cout << mi, 0; long long need = second / n; second %= n; mi -= need; if (second) mi--; cout << mi; }
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 python2 """ This file is part of https://github.com/cheran-senthil/PyRival Copyright 2019 Cheran Senthilkumar <[email protected]> """ from __future__ import division, print_function import math import itertools import os import sys from atexit import register from io import BytesIO class dict(dict): """ dict() -> new empty dictionary """ def items(self): """ D.items() -> a set-like object providing a view on D's items """ return dict.iteritems(self) def keys(self): """ D.keys() -> a set-like object providing a view on D's keys """ return dict.iterkeys(self) def values(self): """ D.values() -> an object providing a view on D's values """ return dict.itervalues(self) def gcd(x, y): """ greatest common divisor of x and y """ while y: x, y = y, x % y return x range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size)) sys.stdout = BytesIO() register(lambda: os.write(1, sys.stdout.getvalue())) input = lambda: sys.stdin.readline().rstrip('\r\n') def main(): n, s = map(int, input().split()) v = sorted(int(i) for i in input().split()) sum_v = sum(v) if sum_v < s: print(-1) return min_v = min(v) max_drink = sum_v - n * min_v if max_drink >= s: print(min_v) return print(min_v - int(math.ceil((s - max_drink) / n))) if __name__ == '__main__': main()
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; int main() { long long int n; cin >> n; long long int s; cin >> s; long long int arr[n]; long long int sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } sort(arr, arr + n); if (s > sum) { cout << "-1" << endl; } else { long long int m = 0; int id = n; for (int i = 1; i < n; i++) { if (arr[i] != arr[0]) { id = i; break; } } for (int i = id; i < n; i++) { m = m + arr[i] - arr[0]; } s = s - m; if (s <= 0) { cout << arr[0] << endl; } else { long long int ans; ans = arr[0] - ceil(s / (n + 0.0)); cout << 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
import sys input = sys.stdin.readline import math def main(): n,s = map(int,input().split()) tab = list(map(int,input().split())) cost = 0 if sum(tab) < s: print(-1) return m = min(tab) for x in range(n): cost += tab[x] - m if cost >= s: print(m) return s -= cost nb_couches = s//n if cost == 0: nb_couches = s//n if nb_couches == 0 or s == 1: print(m-1) else: if s%nb_couches==0: print(m-nb_couches) else: print(m-nb_couches-1) 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 = tuple(map(int,input().split())) v = list(map(int,input().split())) mn = min(v) total = 0 possible = 0 for vi in v: possible += vi - mn total += vi if total < s: print(-1) elif possible >= s: print(mn) else: remain = s-possible print( mn - (remain+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
def kvas(s, lst): ss1, ss2 = sum(lst), 0 if ss1 < s: return -1 a = sorted(lst) for i in range(len(a)): ss2 += a[i] - a[0] if ss2 > s: return a[0] return a[0] - (s - ss2 + len(lst) - 1) // len(lst) N, S = [int(j) for j in input().split()] b = [int(z) for z in input().split()] print(kvas(S, b))
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=sorted(list(map(int,input().split()))) k=0 mi=a[0] for i in range(n): k+=(a[n-i-1]-a[0]) a[n-i-1]-=(a[n-i-1]-a[0]) if k>=s: exit(print(a[0])) else: if sum(a)<(s-k): exit(print(-1)) else: r=(-(-(s-k)//n)) print(a[0]-r)
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.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static class TaskSolver { public static void solve(MyScanner in, MyWriter out) throws IOException { int n = in.nextInt(); long s = in.nextLong(); long[] inp = new long[n]; long low = 0, high = (long) 1e15, ans = -1; for(int i = 0; i < n; i++) { inp[i] = in.nextLong(); high = Math.min(high, inp[i]); } while(low <= high) { long mid = (low + high) / 2; long hand = 0; for(int i = 0; i < n; i++) { if(inp[i] >= mid) { hand += inp[i] - mid; } } if(hand >= s) { ans = mid; low = mid + 1; } else { high = mid - 1; } } out.println(ans); } } public static void main(String[] arg) { try { MyScanner in = new MyScanner(); MyWriter out = new MyWriter(); TaskSolver.solve(in, out); out.close(); } catch (IOException e) { e.printStackTrace(); } } static class MyWriter extends PrintWriter { MyWriter() throws FileNotFoundException { super(System.out); } void printArrayInOneLine(int[] a) { print('['); for (int i = 0; i < a.length; i++) { print(a[i] + " "); } println(']'); } } static class MyScanner { private BufferedReader br; private StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { return null; } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; } } }
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.*; public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); public static void main(String[] args) throws IOException { int n = readInt(); long s = readLong(); int minVolume = Integer.MAX_VALUE; long total = 0; for (int index = 0; index < n; index++) { int volume = readInt(); total += volume; minVolume = Math.min(minVolume, volume); } System.out.println(total - s >= 0 ? (total - s) / n < minVolume ? (total - s) / n : minVolume : "-1"); } static long readLong() throws IOException { in.nextToken(); return (long) in.nval; } static int readInt() throws IOException { in.nextToken(); return (int) in.nval; } }
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
#!/usr/bin/env python # -*- coding: utf-8 -*- # File : b.py # Author : recurze # Date : 22:14 10.12.2018 # Last Modified Date: 22:18 10.12.2018 n, s = [int(x) for x in raw_input().split()] a = list(map(int, raw_input().split())) su = sum(a) if su < s: print -1 else: m = min(a) if su - m*n >= s: print m else: s -= su - m*n from math import ceil print int(m-ceil(float(s)/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> long long int v[1001]; int main() { int i, j, k, n, t, l; long long int min = 1000000001; long long int s, r, d, total = 0; scanf("%d %lld", &n, &s); for (int a = 0; a < n; a++) { scanf("%lld", &v[a]); if (min > v[a]) min = v[a]; total += v[a]; } if (s > total) printf("-1\n"); else if (s == total) printf("0\n"); else { if (((total - s) / n) >= min) printf("%lld\n", min); else printf("%lld\n", ((total - s) / n)); } }
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; long long n, s; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; t = 1; while (t--) { cin >> n >> s; vector<long long> v(n); long long sum = 0; long long mini = INT_MAX; for (long long i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; mini = min(mini, v[i]); } if (sum < s) { cout << -1; continue; } sum = 0; for (long long i = 0; i < n; i++) { sum += (v[i] - mini); } if (sum >= s) { cout << mini; continue; } s -= sum; long long ans = mini; while (s > 0) { s -= n; ans--; } cout << 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
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m, mn, res, sum; cin >> n >> m; long long arr[n]; sum = 0; mn = INT_MAX; for (int i = 0; i < n; i++) { cin >> arr[i]; mn = min(arr[i], mn); sum += arr[i]; } res = mn; if (sum < m) { cout << "-1"; return 0; } if (sum == 0) { cout << "0"; return 0; } for (int i = 0; i < n; i++) { m = m - (arr[i] - mn); if (m <= 0) break; } if (m > 0) { { mn = mn - ((m + n - 1) / n); } } cout << mn << "\n"; }
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; bool comp(pair<int, int> &a, pair<int, int> &b) { if (a.second == b.second) return a.first < b.first; else return a.second < b.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N; long long S; cin >> N >> S; vector<long long> a(N); long long sum1 = 0ll, sum2 = 0ll; for (int i = 0; i < N; ++i) { cin >> a[i]; sum1 += a[i]; } if (sum1 < S) { cout << -1; return 0; } sort(a.begin(), a.end()); for (int i = 0; i < N; ++i) { sum2 += a[i] - a[0]; } if (sum2 >= S) { cout << a[0]; return 0; } S -= sum2; cout << a[0] - ((S - 1ll) / (long long)N + 1ll); return 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
n,s = map(int,input().split()) l = list(map(int,input().split())) l.sort(reverse=True) if sum(l)<s: print(-1) exit() cnt = 0 z = l[-1] for i in range(n): if s == 0: break k = l[i]-z if s>=k: s-=k else: print(z) exit() ka = s//n ans = z-ka if s%n == 0: print(ans) else: print(ans-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,k = [int(j) for j in input().split()] a = [int(j) for j in input().split()] t = min(a) summ = 0 for i in range(n): summ += a[i] psumm = summ-t*n ram = (k-psumm) if ram%n == 0: ans = t-(ram//n) else: ans = t-1-(ram//n) if k>summ: print(-1) elif k<=psumm: print(t) else: 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
'''input 3 4 5 3 4 ''' import math from fractions import gcd n,s=map(int,raw_input().split()) v=map(int,raw_input().split()) v.sort() if sum(v)<s: print -1 else: for i in range(n): if v[i]-v[0]>=s: print v[0] exit(0) else: s-=(v[i]-v[0]) v[i]=v[0] k=s/n z=v[0] z-=k s-=k*n if(s==0): print z else: print z-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
import math n,s = map(int, input().split(" ")) ar = list(map(int, input().split(" "))) sm = sum(ar) if s > sm: print(-1) else: mn = min(ar) ex = (sm - mn) - ((n-1)*mn) if ex >= s: print(mn) else: print(mn - math.ceil((s - ex)/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 INF = 0x3f3f3f3f; const long long int llINF = 0x3f3f3f3f3f3f3f; long long int n, s; vector<long long int> v; bool check(long long int val) { long long int bebe = 0; for (auto x : v) { if (x < val) return false; bebe += abs(x - val); } return bebe >= s; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> s; long long int tot = 0; for (int i = 1; i <= n; i++) { long long int x; cin >> x; v.push_back(x); tot += x; } if (tot < s) { cout << -1 << endl; return 0; } sort(v.begin(), v.end()); long long int ini = 0; long long int end = 1e9; long long int best = -INF; while (ini <= end) { long long int mid = (ini + end) >> 1; if (check(mid)) { best = max(best, mid); ini = mid + 1; } else end = mid - 1; } cout << best << 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] = [int(x) for x in input().split(' ')] v = [int(x) for x in input().split(' ')] v.sort() minV = v[0] totalV = sum(v) if totalV < s: print(-1) else: if totalV - minV * n >= s: print(minV) else: remain = totalV - s print(remain//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() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, ans = 0, acum = 0, s, tonel; cin >> n >> s >> ans; acum = ans; for (int i = 1; i < n; ++i) { cin >> tonel; acum += tonel; ans = min(ans, tonel); } if (acum < s) ans = -1; else if (acum == s) ans = 0; else { s -= (acum - ans * n); while (s > 0) { ans--; s -= n; } } cout << ans << "\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 java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class codeforces { static class Student{ int a,s,gd,gs; Student(int a,int b,int c,int d){ this.a=a; this.s=b; gd=c; gs=d; } } static int sieveOfEratosthenes(int n) { // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will // finally be false if i is Not a prime, else true. int pos=0; boolean prime[] = new boolean[n+1]; for(int i=0;i<=n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { // If prime[p] is not changed, then it is a prime if(prime[p] == true) { // Update all multiples of p for(int i = p*p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for(int i = 2; i <= n; i++) { if(prime[i] == true) ++pos; } return pos; } static class Sortbyroll implements Comparator<Student> { // Used for sorting in ascending order of // roll number public int compare(Student c, Student b) { if(c.s>b.s) return -1; else if(c.s==b.s){ if(c.gd>b.gd) return -1; else if(c.gd==b.gd){ if(c.gs>b.gs) return -1; else if(c.gs==b.gs){ if(c.a>b.a) return -1; else return 1; } } else return 1; } return 1; } } 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; } } public static void main(String[] args){ //long sum=0; int t,n,d,i,q,p,r,pos=0,j,c_0=-1,c_1=-1,si=0,ans2=0,e,x,mid,min,m,h,c_2,c,a1,b; long ans=0,ans1=0,s; String s1; FastReader sc=new FastReader(); n=sc.nextInt(); s=sc.nextLong(); long a[]=new long[n]; for(i=0;i<n;i++) a[i]=sc.nextLong(); Arrays.sort(a); for(i=n-1;i>=0;i--){ s-=a[i]-a[0]; } if(s<=0) System.out.println(a[0]); else{ if(s>n*a[0]) System.out.println(-1); else { if(s%(long)n==0) System.out.println(a[0]-s/(long)n); else System.out.println(a[0]-s/(long)n-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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; public class KVASS { public static void main(String[] args)throws IOException { BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); String s[]=ob.readLine().split(" "); int n=Integer.parseInt(s[0]); long k=Long.parseLong(s[1]); int v[]=new int[n]; String s1[]=ob.readLine().split(" "); int min=Integer.MAX_VALUE; long total=0; for(int i=0;i<n;i++) { v[i]=Integer.parseInt(s1[i]); total+=v[i]; if(v[i]<min) min=v[i]; } // System.out.println("total = "+total); if(total<k) { System.out.println("-1"); return; } long temp=0; for(int i=0;i<n;i++) temp+=(long)(v[i]-min); // System.out.println("temp = "+temp); if(temp>=k) { System.out.println(min); return; } k=k-temp; // System.out.println(" k after temp = "+k); long x=k/n; if(k%n!=0) x++; // System.out.println("x = "+x); total=min-x; System.out.println(total); } }
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 n; int v[1005]; long long s, sum; bool cmp(int x, int y) { return x > y; } int main() { scanf("%d %lld", &n, &s); for (int i = 1; i <= n; i++) scanf("%d", &v[i]), sum += v[i]; if (sum < s) { printf("-1\n"); return 0; } sort(v + 1, v + n + 1, cmp); for (int i = 1; i <= n; i++) { long long vi = (long long)i * (v[i] - v[i + 1]); if (s > vi) s -= vi; else { if (i == n) printf("%d\n", v[i] - (s + i - 1) / i); else printf("%d\n", v[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()) li=input().split() for i in range(n): li[i]=int(li[i]) su=sum(li) if su<s: print(-1) exit(0) if su-s<n: print(0) exit(0) li.sort() k=(su-s)/n k=int(math.floor(k)) if k>li[0]: k=li[0] print(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()) l = [int(i) for i in input().split()] ''' for i in range(n): x = max(l) - s // n l.remove(max(l)) l.append(x) for i in range(s % n): x = max(l) - 1 l.remove(max(l)) l.append(x) if min(l) < 0: print(-1) else: print(min(l)) ''' 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
l = raw_input().split() n, s = int(l[0]), int(l[1]) l = raw_input().split() add = 0 m = 10**18 for i in range(n): l[i] = int(l[i]) add += l[i] m = min(m, l[i]) if add < s: print -1 elif add == s: print 0 else: excess = 0 for i in range(n): excess += (l[i]-m) if excess >= s: print m else: ans = m-(s-excess)/n if (s-excess)%n == 0: print ans else: print ans-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
import java.util.*; import java.io.*; public class B{ public static void main(String[] args) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int n = fs.nextInt(); long s = fs.nextLong(); long[] arr = new long[n]; long sum = 0; long min = Long.MAX_VALUE; for(int i=0;i<n;i++) { arr[i] = fs.nextLong(); sum += arr[i]; min = Math.min(min,arr[i]); } if(sum < s) { out.println("-1"); } else { long my = 0; for(long i:arr) { my += i-min; } long more = s-my; long times = (more+n-1)/n; long ans = min - Math.max(0,times); out.println(ans); } out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } public static int[] sort(int[] arr) { List<Integer> temp = new ArrayList(); for(int i:arr)temp.add(i); Collections.sort(temp,Collections.reverseOrder()); int start = 0; for(int i:temp)arr[start++]=i; return arr; } }
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.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Mufaddal Naya */ 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); BKvassAndTheFairNut solver = new BKvassAndTheFairNut(); solver.solve(1, in, out); out.close(); } static class BKvassAndTheFairNut { 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(); int min = a[0]; for (int i = 0; i < n; i++) if (a[i] < min) min = a[i]; long k = 0; for (int i = 0; i < n; i++) { k += a[i] - min; } if (k >= s) { out.println(min); return; } double g = s - k; g /= n; long kt = (long) Math.ceil(g); if (kt <= min) { out.println((min - kt)); } else { out.println("-1"); } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.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 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 boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
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 ar[1001]; int main() { long long int n, s; cin >> n >> s; for (int i = 1; i <= n; i++) cin >> ar[i]; long long sum = 0; for (int i = 1; i <= n; i++) sum += ar[i]; if (sum < s) { cout << -1 << endl; exit(0); } long long m = *min_element(ar + 1, ar + n + 1); long long diff = sum - m * n; if (diff > s) cout << m << endl; else { s -= diff; int h; if (s % n == 0) h = s / n; else h = s / n + 1; cout << m - h << 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
#include <bits/stdc++.h> using namespace std; long long n, s; vector<long long> v(1001); long long check(long long x) { long long sum = 0; for (long long i = 0; i < n; i++) { if (v[i] < x) return 0; sum += max((long long)0, v[i] - x); } return (sum >= s); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n >> s; for (long long i = 0; i < n; i++) cin >> v[i]; long long l = 0; long long r = 1e15; while (l < r) { long long mid = (l + r + 1) / 2; if (check(mid)) l = mid; else r = mid - 1; } if (check(l)) cout << l; else cout << -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 sys input = sys.stdin.readline n,s=map(int,input().split()) V=list(map(int,input().split())) MIN=min(V) SUM=sum(V) if s>SUM: print(-1) sys.exit() if SUM-MIN*n>=s: print(MIN) sys.exit() print((SUM-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.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class KvassAndTheFairNut { 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; } } public static void main(String[] args) { FastReader sc = new FastReader(); int n = sc.nextInt(); long s = sc.nextLong(); long sum = 0; long[] a = new long[n]; for(int i=0; i<n; i++) { a[i] = sc.nextLong(); sum = sum + a[i]; } if(sum<s) { System.out.println("-1"); } else { Arrays.sort(a); sum = 0; for(int i=1; i<n; i++) { sum = sum + a[i]-a[0]; } if(sum>=s) { System.out.println(a[0]); } else { s = s-sum; long rem = (long)Math.ceil((double)s/(double)n); System.out.println(a[0]-rem); } } } }
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
/* _oo0oo_ o8888888o 88" . "88 (| -_- |) 0\ = /0 ___/`---'\___ .' \\| |// '. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' |_/ | \ .-\__ '-' ___/-. / ___'. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' >' "". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `_. \_ __\ /__ _/ .-` / / =====`-.____`.___ \_____/___.-`___.-'===== `=---=' */ import java.util.function.Consumer; import java.util.*; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.text.DecimalFormat; import java.io.*; import java.lang.Math.*; public class KickStart2020{ 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());} float nextFloat() {return Float.parseFloat(next());} String nextLine() { String str = ""; try {str = br.readLine();} catch (IOException e) { e.printStackTrace();} return str; }} static boolean isBracketSequence(String s, int a, int b) { Stack<Character> ss = new Stack<>(); boolean hachu = true; for(int i = a; i <= b; i++) { if(s.charAt(i) == ')' && ss.isEmpty()) {hachu = false; break;} if(s.charAt(i) == '(') ss.add('('); else ss.pop(); } return ss.empty() && hachu; } static String reverseOfString(String a) { StringBuilder ssd = new StringBuilder(); for(int i = a.length() - 1; i >= 0; i--) { ssd.append(a.charAt(i)); } return ssd.toString(); } static char[] reverseOfChar(char a[]) { char b[] = new char[a.length]; int j = 0; for(int i = a.length - 1; i >= 0; i--) { b[i] = a[j]; j++; } return b; } static boolean isPalindrome(char a[]) { boolean hachu = true; for(int i = 0; i <= a.length / 2; i++) { if(a[i] != a[a.length - 1 - i]) { hachu = false; break; } } return hachu; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long powermod(long x, long y, long mod){ long ans = 1; x = x % mod; if (x == 0) return 0; int i = 1; while (y > 0){ if ((y & 1) != 0) ans = (ans * x) % mod; y = y >> 1; x = (x * x) % mod; } return ans; } static long power(long x, long y){ long ans = 1; if (x == 0) return 0; int i = 1; while (y > 0){ if ((y & 1) != 0) ans = (ans * x); y = y >> 1; x = (x * x); } return ans; } static boolean check(String a) { boolean hachu = true; for(int i = 0; i < a.length(); i++) { if(a.charAt(0) != a.charAt(i)) {hachu = false; break;} } return hachu; } public static class Pair implements Comparable<Pair> { public final int index; public final int value; public Pair(int index, int value) { this.index = index; this.value = value; } @Override public int compareTo(Pair other) { //multiplied to -1 as the author need descending sort order return -1 * Integer.valueOf(this.value).compareTo(other.value); } } static boolean equalString(int i, int j, int arr[], String b) { int brr[] = new int[26]; for(int k = i; k <= j; k++) brr[b.charAt(k) - 'a']++; for(int k = 0; k < 26; k++) { if(arr[k] != brr[k]) return false; } return true; } static boolean cequalArray(String a, String b) { int count[] = new int[26]; int count1[] = new int[26]; for(int i = 0; i < a.length(); i++) count[a.charAt(i) - 'a']++; for(int i = 0; i < a.length(); i++) count1[b.charAt(i) - 'a']++; for(int i = 0; i < 26; i++) if(count[i] != count1[i]) return false; return true; } public static void main(String[] args) throws Exception{ FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); long s = sc.nextLong(); int min = Integer.MAX_VALUE; int arr[] = new int[n]; long sum = 0; for(int i = 0; i < n; i++) { arr[i] = sc.nextInt(); min = Math.min(arr[i], min); sum += arr[i]; } if(sum < s)out.println(-1); else { if(sum - (long)min * n >= s) out.println(min); else { long z = s - sum + (long) min * n; long x = z / n; long d = z % (long)n; if(d == 0) out.println(min - x); else out.println(min - x - 1); } } 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
# -*- coding: utf-8 -*- """ Created on Wed Dec 12 11:09:39 2018 @author: pc """ from math import ceil n,s=map(int,input().split()) x=[int(v) for v in input().split()] t=sum(x) m=min(x) if t<s: print(-1) else: if t-n*m>=s: print(m) else: l=ceil((s-t+n*m)/n) print(m-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
import sys def leastKeg(kegs,s): if sum(kegs)<s: return(-1) kegs.sort() kegs.reverse() mini=kegs[-1] # print(kegs) for i in xrange(len(kegs)): if s>0 : if kegs[i]-mini>=s: s=0 kegs[i]=kegs[i]-s return(mini) else: s-=(kegs[i]-mini) kegs[i]=mini kegs[0]-=s/len(kegs) s-=len(kegs)*(s/len(kegs)) if s!=0: mini=kegs[0]-1 else: mini=kegs[0] return(mini) [n,s]=list(map(int,raw_input().split())) kegs=list(map(int,raw_input().split())) print(leastKeg(kegs,s))
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 java.util.Scanner; public class Codeforces2{ private static int n; private static long s; private static int[] arr; private static Scanner in; public static long findDoable(){ int min=Integer.MAX_VALUE; for(int i=0;i<n;i++){ if(arr[i] < min){ min=arr[i]; } } long got=0; long temp=0; for(int i=0;i<n;i++){ if(arr[i]==min){ continue; } temp=(long)arr[i]-min; got+=temp; if(got >= s){ return (long)min; } } //System.out.println("min "+min); /*for(int k=min;k>0;k--){ got+=n; //System.out.println("got "+got); if(got >= s){ return k-1; } }*/ long minL=(long) min; long r,q; long left=s-got; r=left%n; q=left/n; if(q > minL ){ return -1; } else if(r==0){ return minL-q; } else if(r > 0){ if(minL-q == 0) return -1; return minL-q-1; } return -1; } public static void main(String[] args){ in=new Scanner(System.in); n=in.nextInt(); s=in.nextLong(); arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=in.nextInt(); } System.out.println(findDoable()); } }
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, a[1001]; int main() { while (cin >> n >> s) { long long maxa = 0, sum = 0, mina = 0x3f3f3f3f; for (int i = 0; i < n; i++) { cin >> a[i]; maxa = max(a[i], maxa); mina = min(mina, a[i]); sum += a[i]; } long long l = 0, r = maxa; while (l + 1 < r) { long long mid = (l + r) / 2; if (sum - mid * n >= s) l = mid; else r = mid; } while (r >= 0 && sum - r * n < s) { r--; } cout << min(r, mina) << 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; bool P(long long r, vector<long long> &v, long long &s) { int i; long long sum = 0; for (i = 0; i < v.size(); i++) if (v[i] - r >= 0) sum += v[i] - r; if (sum >= s) return true; return false; } int main() { long long n, s, i, sum = 0; cin >> n >> s; vector<long long> v(n); for (i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } if (sum < s) { cout << -1; return 0; } long long l = 0, h = *min_element(v.begin(), v.end()), ans, mid; while (l <= h) { mid = (l + h) / 2; if (P(mid, v, s)) { ans = mid; l = mid + 1; } else h = mid - 1; } cout << ans; }
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; inline char gch() { static char buf[100010], *h = buf, *t = buf; return h == t && (t = (h = buf) + fread(buf, 1, 100000, stdin), h == t) ? EOF : *h++; } inline void re(long long &x) { x = 0; char a; bool b = 0; while (!isdigit(a = getchar())) b = a == '-'; while (isdigit(a)) x = x * 10 + a - '0', a = getchar(); if (b == 1) x = -x; } long long n, s, ans = -1, a[1010]; inline bool check(long long x) { long long rt = 0; for (register int i = 1; i <= n; i++) { if (a[i] < x) return 0; rt += (a[i] - x); } return rt >= s; } int main() { re(n), re(s); long long l = 0, r = 0; for (register int i = 1; i <= n; i++) re(a[i]), r += a[i]; while (l <= r) { long long mid = (l + r) >> 1; if (check(mid)) ans = mid, l = mid + 1; else r = mid - 1; } cout << ans; }
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; #pragma comment(linker, "/stack:200000000") long long int t, n, m, j, ans, k, a, b, c, d, e, f, sum, i, sz; string s, s2, s3, s4; vector<long long int> v; int ar[(int)(1e6 + 10)], ar2[(int)(1e6 + 10)]; void brainfuck(); int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); brainfuck(); return 0; } void brainfuck() { cin >> n >> m; b = INT_MAX; for (i = 1; i <= n; i++) { cin >> a; v.push_back(a); b = min(a, b); sum += a; } if (sum < m) { cout << "-1"; return; } a = 0; for (i = 1; i <= n; i++) { a += abs(v[i - 1] - b); v[i - 1] = b; } if (m <= a) { cout << b; return; } c = m - a; d = c / n; if (!d) d = 1; if (d * n >= c) { cout << v[0] - d; return; } else cout << v[0] - d - 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
n, size = list(map(int, input().split())) array = list(map(int, input().split())) if (sum(array) - size) < 0: print(-1) else: print(min(min(array), (sum(array) - size) // 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.*; import java.util.*; import java.math.*; public class Main{ //static variable static final int mod = (int) 1e9 + 7; static final double eps = 1e-6; static final double pi = Math.PI; static final long inf = Long.MAX_VALUE / 2; // .......static class static class Pair{ int key,value; Pair(int key,int value){ this.key=key; this.value=value; } int Key(){ return key; } int Value(){ return value; } } static class mycomparator implements Comparator<Pair>{ @Override public int compare(Pair o1,Pair o2){ Integer key1=o1.Key(),key2=o2.Key(); return key1.compareTo(key2); } } //.............staic class end. BufferedReader br; PrintWriter out; public static void main(String[] args) { new Main().main1(); } void main1() { try{ br=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(System.out); int t=1; // t=ii(); while(t-->0){ //........solution start long ns[] = ilong(); long n = ns[0] , s = ns[1]; long a[] = ilong(); long min = getmin(a); long sum = 0; for(int i=0;i<n;i++){ sum+=a[i]; } if(sum<s){ System.out.println("-1"); continue; } long ans = findSol(0,min,sum,n,s); System.out.println(ans); //..........solution end. } out.flush(); out.close(); } catch(Exception e){ e.printStackTrace();} } // ...............required method. long findSol(long l , long r ,long sum,long n , long s){ long mid = 0; long ans = -1; while(l<=r){ mid = l+(r-l)/2; long exp = calcExpire(mid,sum,n); if(exp >= s){ ans = Math.max(ans,mid); l=mid+1; } else { r=mid-1; } } if(ans<0) ans=0; return ans; } int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } long calcExpire(long mid , long sum , long n){ long temp = n*mid; return (sum - temp); } //................end. //..............input method start. int getmax(int a[]){ int n=a.length; int max=a[0]; for (int i=1;i<n ;i++ ) { max=Math.max(a[i],max); } return max; } long getmin(long a[]){ int n=a.length; long min=a[0]; for (int i=1;i<n ;i++ ) { min=Math.min(a[i],min); } return min; } int[] iint() throws IOException{ String line[]=br.readLine().split(" "); int[] a=new int[line.length]; for (int i=0;i<line.length ;i++ ) { a[i]=Integer.parseInt(line[i]); } return a; } long[] ilong() throws IOException{ String line[]=br.readLine().split(" "); long[] a=new long[line.length]; for (int i=0;i<line.length ;i++ ) { a[i]=Long.parseLong(line[i]); } return a; } double[] idouble() throws IOException{ String line[]=br.readLine().split(" "); double[] a=new double[line.length]; for (int i=0;i<line.length ;i++ ) { a[i]=Long.parseLong(line[i]); } return a; } long li() throws IOException{ return Long.parseLong(br.readLine()); } int ii() throws IOException{ return Integer.parseInt(br.readLine()); } double di() throws IOException{ return Double.parseDouble(br.readLine()); } char ci() throws IOException{ return (char)br.read(); } String si() throws IOException{ return br.readLine(); } String[] isa(int n) throws IOException{ String at =si(); return at.split(" "); } double[][] idm(int n, int m) throws IOException{ double a[][] = new double[n][m]; for (int i = 0; i < n; i++) { double[] temp=idouble(); for (int j = 0; j < m; j++) a[i][j] = temp[j]; } return a; } int[][] iim(int n, int m) throws IOException{ int a[][] = new int[n][m]; for (int i = 0; i < n; i++) { int[] temp=iint(); for (int j = 0; j < m; j++) a[i][j] =temp[j]; } return a; } long[][] ilm(int n, int m) throws IOException{ long a[][] = new long[n][m]; for (int i = 0; i < n; i++) { long[] temp=ilong(); for (int j = 0; j < m; j++) a[i][j] =temp[j]; } return a; } //..............input methods end; }
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 def main(): n,s = map(int,input().split()) volume = list(map(int,input().split())) if s > sum(volume): print(-1) return min_val = min(volume) for i in range(n): diff = volume[i]-min_val if s >= diff: volume[i] = min_val s -= diff else: volume[i] -= s s = 0 if s == 0: break if s > 0: remove1 = s//n remove2 = s%n #print(remove1,remove2) print(min_val-remove1-math.ceil(remove2/n)) else: print(min_val) 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
#include <bits/stdc++.h> using namespace std; long long inf = (long long)1e18; long long mod = 1e9 + 7; long long max1 = (long long)1e9; int main() { long long i, j, k, n, m, ct = 0, t, ans = 0; cin >> n >> k; long long sum1 = 0; long long a[n], min1 = 1e18; for (i = 0; i < n; i++) { cin >> a[i]; sum1 += a[i]; if (min1 > a[i]) { min1 = a[i]; j = i; } } if (sum1 < k) cout << "-1"; else { long long sum = 0; for (i = 0; i < n; i++) { if (a[i] != min1) { sum += (a[i] - min1); a[i] = min1; } } long long low = 0, high = min1; while (low <= high) { long long mid = (low + high) / 2; if (sum + mid * n >= k) { ans = mid; high = mid - 1; } else low = mid + 1; } cout << a[0] - ans << 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, s = map(int, input().split()) kvas = list(map(int, input().split())) if s > sum(kvas): print(-1) else: if s <= sum(kvas) - n*min(kvas): print(min(kvas)) else: print(min(kvas) - 1 - (s - sum(kvas) + n*min(kvas) - 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 java.util.Scanner; public class Fairnut2 { public int findmin(int v[],int n) { int min = 0; for(int i=1;i<n;i++) { if (v[i]<v[min]) { min=i; } } return min; } public static void main(String[] args) { Fairnut2 obj=new Fairnut2(); Scanner sc = new Scanner(System.in); int n =sc.nextInt(); long s =sc.nextLong(); int []v= new int[n]; long total=0; for(int i=0;i<n;i++) { v[i]= sc.nextInt(); total=total+v[i]; } int vmin=v[obj.findmin(v,n)]; if(total-s<0) { System.out.println(-1); } else if(((total-s)/n)>=vmin) { System.out.println(vmin); } else { vmin= (int) ((total-s)/n); System.out.println(vmin); } } }
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()) l = map(int, raw_input().split()) if sum(l) < s: print -1 else: if s <= sum(l)-min(l)*n: print min(l) else: print (sum(l)-s)/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
import java.util.Scanner; public class KvassAndTheFairNut { public static void main(String[] args) { Scanner in = new Scanner(System.in); int numKegs = in.nextInt(); long vol = in.nextLong(); int min = Integer.MAX_VALUE; for(int i = 0; i < numKegs; i++) { int tmp = in.nextInt(); vol -= tmp; min = min > tmp ? tmp : min; } if(vol > 0) { System.out.println("-1"); } else { System.out.println(Math.min(vol/numKegs*-1, 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; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; t = 1; while (t--) solve(); return 0; } void solve() { long long i, j, n, s; cin >> n >> s; vector<long long> a(n); long long small, tot = 0; for (i = 0; i < n; ++i) { cin >> a[i]; tot += a[i]; } small = *min_element(a.begin(), a.end()); if (s > tot) { cout << -1; return; } for (i = 0; i < n; ++i) s -= a[i] - small; if (s <= 0) { cout << small; return; } if (s % n) cout << small - (s / n) - 1; else cout << small - s / n; }
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 main() { long long n, s; cin >> n >> s; long long a[n]; long long sumofa = 0; long long minofa = INT_MAX; for (long long i = 0; i < n; i++) { cin >> a[i]; sumofa += a[i]; if (minofa > a[i]) { minofa = a[i]; } } if (sumofa < s) { cout << -1 << endl; } else if (sumofa == s) { cout << 0 << endl; } else { long long temp = sumofa - (n * minofa); if (temp >= s) { cout << minofa << endl; } else { long long cnt = s - temp; long long res = ((n * minofa) - cnt) / n; cout << res << 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
a,b=map(int,input().split()) z=list(map(int,input().split())) s=sum(z);r=min(z) if b>s:print(-1) else:print(min(r,(s-b)//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; template <typename X> inline X sqr(const X& a) { return a * a; } int nxt() { int x; cin >> x; return x; } int main() { int n = nxt(); long long s; cin >> s; vector<int> a(n); generate(a.begin(), a.end(), nxt); if (accumulate(a.begin(), a.end(), 0ll) < s) { cout << -1 << '\n'; return 0; } int mn = *min_element(a.begin(), a.end()); for (int i = 0; i < int(n); ++i) { s -= a[i] - mn; } s = max(s, 0ll); cout << mn - (s + n - 1) / n << '\n'; return 0; }
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; long long num[1005]; int main() { long long n, k; while (~scanf("%lld%lld", &n, &k)) { long long minn = 0x3f3f3f3f, sum = 0; for (int i = 0; i < n; i++) { scanf("%lld", &num[i]); minn = min(minn, num[i]); sum += num[i]; } if (sum < k) printf("-1\n"); else if (sum == k) printf("0\n"); else { long long ans = 0; for (int i = 0; i < n; i++) ans += num[i] - minn; if (ans >= k) printf("%lld\n", minn); else { long long tmp = ceil((k - ans) * 1.0 / n); printf("%lld\n", minn - tmp); } } } return 0; }
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 a{ static Scanner sc=new Scanner(System.in); public static void main(String [] args){ int n=sc.nextInt(); long s=sc.nextLong(); long [] v=new long[n]; long sum=0; long min=Integer.MAX_VALUE; long max=Integer.MIN_VALUE; for(int i=0;i<n;i++){ v[i]=sc.nextLong(); sum+=v[i]; min=Math.min(min,v[i]); max=Math.max(max,v[i]); } if(sum<s){ System.out.println(-1); } else{ long diff=0; for(int i=0;i<n;i++){ diff+=v[i]-min; } long ans=1; if(diff>=s){ ans=min; } else{ s=s-diff; long x=s/n; if(x<=min){ ans=min-x; min-=x; if(s%n!=0){ if(min>0){ ans-=1; }else{ ans=-1; } } } else{ ans=-1; } } System.out.println(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
#include <bits/stdc++.h> using namespace std; long long N, s, v[1010]; int main() { cin >> N >> s; long long minval = numeric_limits<long long>::max(); for (int i = 0; i < N; i++) { cin >> v[i]; minval = min(minval, v[i]); } long long starttotal = 0; for (int i = 0; i < N; i++) { starttotal += v[i] - minval; } if (starttotal + minval * N < s) { cout << -1 << endl; return 0; } s -= starttotal; if (s <= 0) { cout << minval << endl; return 0; } cout << minval - (long long)ceil((double)s / (double)N) << endl; return 0; }
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, V = map(int, input().split()) s = list(map(int, input().split())) if sum(s) < V: print(-1) else: s.sort() summ = 0 m = min(s) F = False for el in s[1:]: summ += el - m if summ >= V: F = True break if F: print(m) else: ost = V - summ print(int(m - ost/len(s)))
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 sys import math,bisect sys.setrecursionlimit(10 ** 5) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict def I(): return int(sys.stdin.readline()) def neo(): return map(int, sys.stdin.readline().split()) def Neo(): return list(map(int, sys.stdin.readline().split())) n,s = neo() A = Neo() m = min(A) if sum(A) < s: print(-1) exit() for i in range(n): s -= (A[i]-m) if s <= 0: print(m) else: t = math.ceil(s/n) print(m-t)
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 { static Scanner sc = new Scanner(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int n = sc.nextInt(); long s = sc.nextLong(); int[] v = new int[n]; int min = Integer.MAX_VALUE; for(int i = 0; i < n; i++) min = Math.min(min, v[i] = sc.nextInt()); int lo = 0, hi = min, best = -1; while(lo <= hi) { int mid = lo + hi >> 1; long sumOfDifferences = 0; for(int i = 0; i < n; i++) sumOfDifferences += v[i] - mid; if(sumOfDifferences >= s){ best = mid; lo = mid + 1; }else hi = mid - 1; } out.println(best); out.flush(); out.close(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } 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
n,m=map(int,input().split()) a=list(map(int,input().split())) s=sum(a) k=min(a) if s<m: print(-1) else: p=s-m print(min(k,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
n, s = map(int, input().split()) arrv = list(map(int, input().split())) sumv, minv = sum(arrv), min(arrv) if sumv < s: print(-1) else: k = (sumv - s) // n print (min(k, minv))
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 N = 1123; long long v[N]; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; long long s; cin >> s; for (int i = 0; i < n; i++) cin >> v[i]; long long sum = 0, mn = LLONG_MAX; for (int i = 0; i < n; i++) { mn = min(mn, v[i]); sum += v[i]; } if (sum < s) { cout << -1 << endl; return 0; } long long cur = 0; for (int i = 0; i < n; i++) { cur += v[i] - mn; v[i] = mn; } if (cur >= s) { cout << mn << endl; return 0; } cout << mn - (s - cur + n - 1) / n << endl; return 0; }
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
# Lets goto the next level # AIM Specialist at CF *__* asap # template taken from chaudhary_19 # Remember you were also a novice when you started, # hence never be rude to anyone who wants to learn something # Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts # Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure. # Any doubts or want to have a talk, contact https://www.facebook.com/chaudhary.mayank # ///==========Libraries, Constants and Functions=============/// import sys from bisect import bisect_left,bisect_right,insort from collections import deque,Counter from math import gcd,sqrt,factorial,ceil,log10,log2,floor from itertools import permutations from heapq import heappush,heappop,heapify inf = float("inf") mod = 10**9+7 #sys.setrecursionlimit(10**9) def factorial_p(n, p): ans = 1 if n <= p // 2: for i in range(1, n + 1): ans = (ans * i) % p else: for i in range(1, p - n): ans = (ans * i) % p ans = pow(ans, p - 2, p) if n % 2 == 0: ans = p - ans return ans def nCr_p(n, r, p): ans = 1 while (n != 0) or (r != 0): a, b = n % p, r % p if a < b: return 0 ans = (ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p)) % p n //= p r //= p return ans def prime_sieve(n): """returns a sieve of primes >= 5 and < n""" flag = n % 6 == 2 sieve = bytearray((n // 3 + flag >> 3) + 1) for i in range(1, int(n**0.5) // 3 + 1): if not (sieve[i >> 3] >> (i & 7)) & 1: k = (3 * i + 1) | 1 for j in range(k * k // 3, n // 3 + flag, 2 * k): sieve[j >> 3] |= 1 << (j & 7) for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k): sieve[j >> 3] |= 1 << (j & 7) return sieve def prime_list(n): #<----- You have to call me if you wanna get list of primes upto range n """returns a list of primes <= n""" res = [] if n > 1: res.append(2) if n > 2: res.append(3) if n > 4: sieve = prime_sieve(n + 1) res.extend(3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not (sieve[i >> 3] >> (i & 7)) & 1) return res def is_prime(n): """returns True if n is prime else False""" if n < 5 or n & 1 == 0 or n % 3 == 0: return 2 <= n <= 3 s = ((n - 1) & (1 - n)).bit_length() - 1 d = n >> s for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: p = pow(a, d, n) if p == 1 or p == n - 1 or a % n == 0: continue for _ in range(s): p = (p * p) % n if p == n - 1: break else: return False return True def all_factors(n): """returns a sorted list of all distinct factors of n""" small, large = [],[] for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1): if not n % i: small.append(i) large.append(n//i) large.reverse() small.extend(large) return small def count(n): return ((n*(n+1))//2) def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() # ///===========MAIN=============/// n,s=get_ints() Arr=get_array() total=sum(Arr) if total<s: print(-1) exit() left=0;mini=min(Arr) for i in range(n): left+=(Arr[i]-mini) if left>=s: print(mini) exit() else: s=s-left think=mini-(s//n) if s%n!=0: think-=1 print(think)
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; cin >> n >> s; long long int min = INT_MAX; unsigned long long int sum = 0; long long int i; long long int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; if (arr[i] < min) min = arr[i]; } if (sum < s) { cout << "-1"; return 0; } if (sum == s) { cout << "0"; return 0; } long long int count = 0; for (i = 0; i < n; i++) { if (arr[i] > min) count++; } for (i = 0; i < n; i++) { if (count <= 0) break; if (arr[i] > min) { count -= 1; if (s - (arr[i] - min) <= 0) { cout << min; return 0; } s = s - (arr[i] - min); arr[i] = min; } } while (s != 0 && min >= 0) { if (s - (n) <= 0) { cout << (min - 1); return 0; } else { min--; s = s - n; } } cout << "-1"; return 0; }
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.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Cf182 implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 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() { 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 Cf182(),"Main",1<<27).start(); } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } // array sorting by colm public static void sortbyColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else return -1; } }); } // gcd public static long findGCD(long arr[], int n) { long result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result); return result; } // fibonaci static int fib(int n) { int a = 0, b = 1, c; if (n == 0) return a; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } // sort a string public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static long power(long x, long y) { if (y == 0) return 1; long temp = power(x, y / 2); if (y % 2 == 0) return temp*temp; else return x * temp * temp; } // pair function // list.add(new Pair<>(sc.nextInt(), i + 1)); // Collections.sort(list, (a, b) -> Integer.compare(b.first, a.first)); private static class Pair<F, S> { private F first; private S second; public Pair() {} public Pair(F first, S second) { this.first = first; this.second = second; } } public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = sc.nextInt(); long s = sc.nextLong(); int a[] = new int[n]; long sum = 0; int min = Integer.MAX_VALUE; for(int i=0;i<n;i++) { a[i] = sc.nextInt(); sum += a[i]; if(a[i]<min) min = a[i]; } if(sum<s) System.out.println("-1"); else { long target = 0; for(int i=0;i<n;i++) target += (a[i] - min); if(s<=target) System.out.println(min); else { long x = s - target; x = (long)Math.ceil((double)x/n); System.out.println(min-x); } } } }
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
#codeforces _1084B_live gi = lambda : list(map(int,input().split())) n,s = gi() l = gi() l.sort(reverse=True) mii = min(l) cur = 0 while s and cur < n: s -= (l[cur]-mii) cur += 1 cur = 0 if s < 0: print(mii) exit() if s > mii * n: print(-1) exit() temp = s//n if s%n: temp += 1 print(mii-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
n,k = map(int,input().split()) l = list(map(int,input().split())) m , s = min(l) ,sum(l) if s < k: print(-1) else: print(min(m,(s-k)//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 m,n=map(int,input().split()) li=sorted(list(map(int,input().split()))) l=li[0] bli=[] if sum(li)<n: print(-1) exit() for i in range(len(li)): bli.append(li[i]-li[0]) if sum(bli)>=n: print(l) else: print(l-math.ceil((n-sum(bli))/m))
PYTHON3