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;}