第一行输入两个整数
。
接下来
行,第
行输入两个整数
,描述第
张优惠券。
输出一个整数,表示小红使用最优策略后需支付的最少金额。
100 3 300 50 200 30 50 5
95
仅第三张券可用,支付元。
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);
}
} n,m = map(int,input().split()) lis_a = [] lis_b = [] lis_c = [0] for i in range(m): a,b = map(int,input().split()) lis_a.append(a) lis_b.append(b) for j in range(len(lis_a)): if lis_a[j] <= n: lis_c.append(lis_b[j]) res = n - max(lis_c) print(res)
#include <iostream>
using namespace std;
int main() {
int n,m;//100 元 m张
cin>>n;
cin>>m;
int arry[m][2];
for(int i=0;i<m;i++){
cin>>arry[i][0];
cin>>arry[i][1];
}
int minN=n;
for(int j=0;j<m;j++){
if(n>=arry[j][0]){
int tmp=n-arry[j][1];
if(tmp<minN){
minN=tmp;
}
}
}
cout<<minN;
}
// 64 位输出请用 printf("%lld") import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int totalPrice = in.nextInt();
int ticketNum = in.nextInt();
int[][] nums = new int[ticketNum][2];
for (int i = 0; i < ticketNum; i++) {
nums[i][0] = in.nextInt();
nums[i][1] = in.nextInt();
}
int minPrice = Integer.MAX_VALUE;
for (int i = 0; i < ticketNum; i++) {
if (nums[i][0] <= totalPrice) {
minPrice = Math.min(minPrice, totalPrice - nums[i][1]);
}
}
System.out.println(minPrice == Integer.MAX_VALUE ? totalPrice : minPrice);
}
}
} #include <iostream>
#include <map>
#include <set>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
multimap<int,int> k;
for(int i=1;i<=m;i++){
int a,b;
cin>>a>>b;
k.insert({a,b});
}
int flag=0;
set<int> t;
for(auto it=k.rbegin();it!=k.rend();it++){
if(it->first<=n){
t.insert(n-it->second);
}//不需要再加购时的最低
else if(it->first>n){
t.insert(it->first-it->second);
}//加购后的最低
}
if(t.empty()||(*t.begin()>n)){
cout<<n;
}else{
cout<<*t.begin();
}
}
// 64 位输出请用 printf("%lld") #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, m, maxi = 0;
cin >> n >> m;
while(m--){
int a, b;
cin >> a >> b;
//如果满足使用条件
if(a <= n){
//维护最大优惠价格
maxi = max(maxi, b);
}
}
cout << n - maxi;
return 0;
}
// 64 位输出请用 printf("%lld") 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);
}
}