1042A - Benches - CodeForces Solution


binary search implementation *1100

Please click on ads to support us..

Python Code:

from math import ceil
n = int(input()); ap = int(input())
l = [*(int(input()) for i in range(n))]
m = max(l)
s = [*(m-x for x in l)]
sums = sum(s); ap1 = max(ap-sums,0)
mik = max(m,m+ceil(ap1/n))
print(mik,m+ap)

C++ Code:

#include <bits/stdc++.h> 
using namespace std;
using i64 = long long;
const int N = (int)(2e5 + 10);
i64 t[4 * N];
//i64 a[N];
i64 ans = LONG_MIN;
i64 p[N];
vector<i64> sz(N) ;

void solve() { 
	int n, m;
	cin >> n >> m;

	vector<int> vi(n);
	int mx = -1;
	for (int i = 0; i < n; i++) {
	    cin >> vi[i];
	    mx = max(mx, vi[i]);
	} 

	int resMax = mx + m;
	for (int i = 0; i < m; i++) {
		sort(vi.begin(), vi.end());
		vi[0] += 1;	
	} 

	int resMin = INT_MIN;
	for (int i = 0; i < n; i++) {
		resMin = max(resMin, vi[i]);
	} 



	
	cout << resMin << " " << resMax;



}                                                                            	
  
                                                                                                             	
int main() {                                                      
	std::ios::sync_with_stdio(false); 
	std::cin.tie(nullptr);           
   	// freopen("A.in", "r", stdin); 
   	// freopen("A.out", "w", stdout);
	int t = 1;
	
	while (t--) solve();
                                                                      
}                      	                   


Comments

Submit
0 Comments
More Questions

1528B - Kavi on Pairing Duty
339B - Xenia and Ringroad
189A - Cut Ribbon
1182A - Filling Shapes
82A - Double Cola
45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel