Latest Updates ☛
  • Graphs: Introduction of graphs and types of graphs
  • SPOJ : Geeky solves geeky solution
  • Solution Code : Pass the time problem on SPOJ.
  • Find the minimum shortest path solution in c language ! !

Saturday, September 7, 2013

Problem - Pass the time with maximum fun after movie - Solution



Question :
Joey just got free from a shooting and he wants to have a lunch. Director of the movie gave him only "K" units of time for the lunch. There are "N" restaurants in the city. For the ith restuarant, there are two values that Joey knows, "Fi" and "Ti". Ti is the amount of time it would take if Joey eats the lunch in the ith restuarant. If Ti is less than or equal to K, Joey will have Fi amount of fun in that restuarant. If Ti is greater than K, then Joey's fun will be calculated as Fi - (Ti - K).
Joey has the list of all restaurants and Fi and Ti values for all of them. Please tell him the Maximum fun that he can have. He will have his lunch in only one restaurant. The maxiumum can be negative also.

Inputs
First Line will contain two integers N and K. Each of the next N lines will contain two integers Fi and Ti.

Outputs :
Print a single integer that tells the maximum fun that Joey can have.

Constraints
1 <= N <= 10^4, 1 <= K <=10^9, 1 <= Fi,Ti <=10^9




Level :Starter,Cakewalk

Solution to the Problem :


#include<stdio.h>

int arr[10001];

void preprocess()
{
     arr[1]=10;
     int i;
     for(i=2;i<=10000;i++)
     arr[i]=(arr[i-1]*10)%21;
}

void print(int k)
{
     //printf("%d\n",arr[k-2]);
     int x=arr[k-2];
     printf("1");
     int i;
     for(i=1;i<=k-4;i++)
     printf("0");
     if(x==0)
     printf("000");
     else
     {
         x=21-x;
         if(x<10)
         {
                 printf("0%d0",x);
         }
         else
         {
             printf("%d0",x);
         }
     }
     printf("\n");
}

main()
{
      preprocess();
      int k;
      scanf("%d",&k);
      if(k==1||k==2)
      printf("-1\n");
      else if(k==3)
      printf("210\n");
      else if(k==4)
      printf("1050\n");
      else
      print(k);
     
}



Privacy Policy | Disclaimer | Terms of Service

Copyright © 2013, Code Author. Powered by Blogger.