We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

You should do two additional per element subtractions by "mini - 1" and "mini - 2" where the smallest element becomes 1 and 2 instead of 0.

Considering the input
1
3
1 5 5
it's not beneficial to transform the array to zero baseline shape 0 4 4 since the algorithm will break the two fours into two 2s resulting in four operations. Correct answer would be three operations.

intcount_operations(vector<int>counts_choc){intmin_elem=*min_element(begin(counts_choc),end(counts_choc));intn_ops0=0;//number of operation assuming base 0intn_ops1=0;//number of operation assuming base 1intn_ops2=0;//number of operation assuming base 2for(intcolleague=0;colleague<counts_choc.size();colleague++){counts_choc[colleague]-=min_elem;//smallest element 0n_ops0+=counts_choc[colleague]/5;n_ops0+=(counts_choc[colleague]%5)/2;n_ops0+=(counts_choc[colleague]%5)%2;counts_choc[colleague]++;//smallest element 1n_ops1+=counts_choc[colleague]/5;n_ops1+=(counts_choc[colleague]%5)/2;n_ops1+=(counts_choc[colleague]%5)%2;counts_choc[colleague]++;//smallest element 2n_ops2+=counts_choc[colleague]/5;n_ops2+=(counts_choc[colleague]%5)/2;n_ops2+=(counts_choc[colleague]%5)%2;}returnmin(n_ops0,min(n_ops1,n_ops2));}intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intn_tests;cin>>n_tests;vector<vector<int>>data;for(inttest=0;test<n_tests;test++){intn_colleagues;cin>>n_colleagues;vector<int>counts_choc;for(intcolleague=0;colleague<n_colleagues;colleague++){intcount;cin>>count;counts_choc.push_back(count);}data.push_back(counts_choc);}for(inttest=0;test<n_tests;test++){cout<<count_operations(data[test])<<endl;}return0;}

## Equal

You are viewing a single comment's thread. Return to all comments →

You should do two additional per element subtractions by "mini - 1" and "mini - 2" where the smallest element becomes 1 and 2 instead of 0.

Considering the input 1 3 1 5 5 it's not beneficial to transform the array to zero baseline shape 0 4 4 since the algorithm will break the two fours into two 2s resulting in four operations. Correct answer would be three operations.

1 3 602 437 152 if this case is given than...... what i have to do? i can reduce the no of chocklates by 1,2 or 5