Polycarpus' Dice
###################################EDITORIAL#########################
NOTE ANY DICE CAN HAVE TO SHOW MINIMU 1 AND ANY DICE CAN MAXIMIU SHOW UP TO (M-N+1)(SINCE IF REST ALL THE DICE SHOW 1 TAH THIS DICE CAN SHOW M-N+1)
NOTE -- minum is not 1 always if all dice cant fill requirement then min= m-sum+arr[i] .. example 2 11 6 6 in this case min for both dice is 5 . and max in 11-1=10..
now if the valu of ith dice is <min than ith dice will hide min-1 element ie 0 ellements if min=1else if min<= arr[i <=max in this case also dice can have to hoide min-1 ..
but if(arr[i]>max) than ith dice have to hide min-1+arr[i]-max..................
(try to test some case than it will be clear )
######################################CODE##############
NOTE ANY DICE CAN HAVE TO SHOW MINIMU 1 AND ANY DICE CAN MAXIMIU SHOW UP TO (M-N+1)(SINCE IF REST ALL THE DICE SHOW 1 TAH THIS DICE CAN SHOW M-N+1)
NOTE -- minum is not 1 always if all dice cant fill requirement then min= m-sum+arr[i] .. example 2 11 6 6 in this case min for both dice is 5 . and max in 11-1=10..
now if the valu of ith dice is <min than ith dice will hide min-1 element ie 0 ellements if min=1else if min<= arr[i <=max in this case also dice can have to hoide min-1 ..
but if(arr[i]>max) than ith dice have to hide min-1+arr[i]-max..................
(try to test some case than it will be clear )
######################################CODE##############
#include<iostream> using namespace std; #include<bits/stdc++.h> #define first ff #define second ss typedef long long int lli; lli arr[1000000]; int main() { long long int n,m; cin>>n>>m; lli sum=0; for(lli i=0;i<n;i++) { cin>>arr[i]; sum+=arr[i]; } if(n==1) { if(m<=arr[0]) cout<<arr[0]-1<<endl; else cout<<arr[0]<<endl; } else { // cout<<sum<<endl; for(lli i=0;i<n;i++) { lli min; if(m-sum+arr[i]<=0) min=1; else min=m-sum+arr[i]; lli max=m-n+1; // lli req=m-max; if(arr[i]<min) cout<<arr[i]<<" "; else if(arr[i]>=min && arr[i]<=max) { if(min) cout<<min-1<<" "; } else { cout<<min-1+arr[i]-max<<" "; } } } }
No comments:
Post a Comment