[CodeForces - 276A] Lunch Rush

题目链接:http://codeforces.com/problemset/problem/276/A

从这n个输入中求最大值,注意 和 k的比较,定义一个maxn,对每个输入进行计算即可。

AC代码:

#include<cstdio>
#include<climits>

using namespace std;

/* 获取int型数据的最大值最小值有两种方式
 * 第一种是利用头文件<climits>
 * 第二种直接定义或者宏定义
 * INT_MAX = 2147483647
 * INT_MIN = -2147483648
 * #define INT_MAX 0x7fffffff
 * #define INT_MIN 0x80000000
 */

int n, k;
int x, y;
int maxn, temp;

int main() {
    while (scanf("%d%d", &n, &k) != EOF) {
        maxn = INT_MIN;
        while (n--) {
            scanf("%d%d", &x, &y);
            if (y > k) {
                temp = x - (y - k);
            } else
                temp = x;
            if (maxn < temp)
                maxn = temp;
        }
        printf("%d\n", maxn);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/youpeng/p/10720306.html