第一行输入两个整数
。
接下来
行,第
行输入两个整数
,描述第
张优惠券。
输出一个整数,表示小红使用最优策略后需支付的最少金额。
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)
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);
}
} package main
import (
"fmt"
)
func main() {
n, m := 0,0
fmt.Scan(&n, &m)
if m == 0 || n == 0 {
fmt.Println(n)
return
}
yhqs := [][2]int{}
for {
aj,bj := 0,0
n, _ := fmt.Scan(&aj, &bj)
if n == 0 {
break
}
yhq := [2]int{aj, bj}
yhqs = append(yhqs, yhq)
}
// fmt.Println(n, m, yhqs)
min := n // 最低价
for _, v := range yhqs {
yhj := n // 当前优惠券的优惠价
if n >= v[0] {
yhj -= v[1]
}
if min > yhj {
min = yhj
}
}
fmt.Println(min)
} 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]);
}
} #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n,m;
cin >> n >> m;
//为啥要排序啊,。找到一张最大的优惠券不就行了。。。
int max_dis = 0;
for (int i = 0, a,b; i<m; ++i)
{
cin >> a >> b;
if (n >= a)
{
max_dis = max(max_dis, b);
}
}
cout << n - max_dis;
}
// 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 的区别
Map<Integer, Integer> map = new TreeMap<>();
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
int b = in.nextInt();
for (int i = 0; i < b; i++) {
map.put(in.nextInt(),in.nextInt());
}
int x =0;
int y =0;
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
if (a >= entry.getKey()){
x = entry.getKey();
y = y > entry.getValue() ? y : entry.getValue();
}else {
break;
}
}
if(x != 0){
System.out.print(a - y);
}else {
System.out.println(a);
}
}
}
}