第一行输入两个整数
。
接下来
行,第
行输入两个整数
,描述第
张优惠券。
输出一个整数,表示小红使用最优策略后需支付的最少金额。
100 3 300 50 200 30 50 5
95
仅第三张券可用,支付元。
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
TreeMap<Integer, Integer> map = new TreeMap<>();
for (int i = 0; i < m; i++) {
map.put(in.nextInt(), in.nextInt());
}
int dis = 0;
for (int k : map.keySet()) {
if (k > n) {
break;
}
dis = Math.max(dis, map.get(k));
}
System.out.println(n - dis);
}
} import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(); // 结算金额
int m = in.nextInt(); // 卷的个数
int[] a = new int[m];
int[] b = new int[m];
int ans = 1000001;
int res = 0;
for (int i = 0; i < m; i++) {
a[i] = in.nextInt();
b[i] = in.nextInt();
if (n >= a[i]){ // 符合满减条件
res = n - b[i];
}else{ // 不符合
res = n; // 优惠卷可以不用呀
}
ans = Math.min(ans,res);
}
System.out.println(ans);
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int amount = in.nextInt();
int n = in.nextInt();
int max = 0;
while (n-- > 0) {
int limit = in.nextInt();
int discount = in.nextInt();
if (limit > amount) continue;
max = Math.max(max, discount);
}
System.out.println(amount - max);
}
} import java.util.*;
import java.io.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String[] line1=bf.readLine().split(" ");
int n=Integer.parseInt(line1[0]);
int m=Integer.parseInt(line1[1]);
//遍历统计哪些优惠券可用,可用的优惠劵再判断其优惠金额是否最大
int[] discount=new int[]{n,0};
while(m>0){
String[] line=bf.readLine().split(" ");
int disN=Integer.parseInt(line[0]);
int disM=Integer.parseInt(line[1]);
if(disN<=n&&disM>discount[1]){
discount[0]=disN;
discount[1]=disM;
}
m--;
}
System.out.println(n-discount[1]);
}
}