UVa – 11850 – Alaska

Note:

During solving the problem, I was too confused about two things and faced difficulty due to those. And the realizations are:

  1. Here, it is not mentioned in the problem that whether there is any station in the Delta junction or not. In the solution, it has to be assumed that there is no station in the Delta Junction.
  2. Here, it is stated that the car can travel up to 200 miles once charged, not greater than this limit. So here it is not meant that, at one station, the car takes charge for 200 miles. For how many miles the car is taking charge, it is not mentioned and it is not even the fact. The summary is, the car can travel up to 200 miles at once, not more than that.

Solution:

/*
  Author: Arunima Mandal
*/

#include <bits/stdc++.h>

using namespace std;

bool myfunc(int i,int j)
{
    return (i>j);
}

int main()
{
    int i,j,n,p,q,c,x;
    while(cin>>n)
    {
        if(n==0) break;
        int a[n];
        for(i=0; i<n; i++) cin>>a[i];
        sort(a,a+n);
        c=0;
        for(i=0,j=i+1; i<n-1; i++,j++)
        {

            x=a[j]-a[i];
            if(x>200)
            {
                c=0;
                break;
            }
            if(x<=200) c++;
        }
        if(c==0) cout<<"IMPOSSIBLE"<<endl;
        else
        {
            p=1422-a[n-1];
            q=200-p;
            if(q>=p) cout<<"POSSIBLE"<<endl;
            else cout<<"IMPOSSIBLE"<<endl;
        }
    }
    return 0;
}

Leave a comment