POPSICLES-Editorial

Problem Link: Selling Popsicles - Problems - CodeChef

Author: gayathri_anant

Let the maximum of the existing prices p_1, p_2, p_3 …, p_n be p_m and the least cost at which Ram can sell be c.

|p_m-c|\leq10.
As p_i\leq p_m for all i the above condition implies |p_i-c|\leq10.
Therefore finding c translates to solving
p_m-c \leq 10
p_m-10 \leq c
Hence the minimum value of c=p_m-10

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        int p, pmax=0;
        cin>>n;
        for(int i=0;i<n;++i)
        {
            cin>>p;
            if(p>pmax) pmax=p;
        }
        cout<<pmax-10<<endl;
    }

    return 0;
}
2 Likes