A. lunch rush

Source: Internet
Author: User
Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Having written another programming contest, three rabbits decided to grab some lunch. The coach gave the team exactlyKTime units for
Lunch break.

The rabbits have a listNExplain ants to lunch in:I-Th
Restaurant is characterized by two integersFIAndTI.
ValueTIShows
The time the rabbits need to lunch inI-Th restaurant. If timeTIExceeds
The timeKThat the coach has given for the lunch break, then the rabbits 'joy from lunching in this restaurant will equalFIAudio-extract -(TIAccept-Encoding-K).
Otherwise, the rabbits get exactlyFIUnits
Of joy.

Your task is to find the value of the maximum joy the rabbits can get from the lunch, depending on the restaurant. The rabbits must choose exactly one restaurant to lunch in. Note that the joy
Value isn' t necessarily a positive value.

Input

The first line contains two space-separated integers-N(1 digit ≤ DigitNLimit ≤ limit 104)
AndK(1 digit ≤ DigitKLimit ≤ limit 109)
-The number of parameter ants in the rabbits 'list and the time the coach has given them to lunch, correspondingly. Each of the nextNLines
Contains two space-separated integers-FI(1 digit ≤ DigitFILimit ≤ limit 109)
AndTI(1 digit ≤ DigitTILimit ≤ limit 109)
-The characteristics ofI-Th restaurant.

Output

In a single line print a single integer-the maximum Joy value that the rabbits will get from the lunch.

Sample test (s) Input
2 53 34 5
Output
4
Input
4 65 83 62 32 2
Output
3
Input
1 51 7
Output
-1

Problem description: This is to judge a maximum value. You do not need to record all values. You only need to record a maximum value.

#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int main(){int i,n;double k,max;double f,t,temp;scanf("%d %lf",&n,&k);max=-1000000000;for(i=0;i<n;i++){scanf("%lf %lf",&f,&t);if(t>k){temp=f-(t-k);}else{temp=f;}if(temp>max){max=temp;}}printf("%.0lf\n",max);    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.