➤ Problem Link : 348A. Mafia
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int bool func(ll val, ll arr[],ll n) { ll sum=0; if( arr[n-1] > val ) return 0; for(ll i=0;i<n;i++) { sum+=val-arr[i]; if(sum >= val ) return 1; } return 0; } int main() { int n; cin>>n; ll arr[n]; for(int i=0;i<n;i++) cin>>arr[i]; sort(arr,arr+n); ll low=0,high=pow(10,15); ll mid; while(low<high) { mid=low+(high-low)/2; if(func(mid,arr,n)) high=mid; else low=mid+1; } cout<<low; }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!