CSP认证考试202303-2求问

我的代码是过了70%,还有30%没过,不清楚为什么,M开的是long类型

import java.util.Scanner;

public class Main {
    public static int sunZaoMax(int[][] arr){
        int max=0;
        for(int i=0;i<arr.length;i++){
            if(arr[max][0]<arr[i][0]){
                max=i;
            }
        }
//        System.out.println("max"+max+"    arr[max][0]"+arr[max][0]);
        return max;
    }
    public static void main(String[] args){
        long n,m,k;
        // 三个正整数 n。m和 k.分别表示待开垦的区域总数、顿顿手上的资源数量和每块区域的最少开垦天数。
        Scanner sc =new Scanner(System.in);
        n = sc.nextLong();
        m = sc.nextLong();
        k = sc.nextLong();
//两个正整数 和 ,分别表示第 块区域开垦耗时和将耗时缩短 天所需资源数量。
        int[][] arr = new int[(int)n][2];
        for (int i = 0; i < n; i++) {
            arr[i][0]=sc.nextInt();
            arr[i][1]=sc.nextInt();
        }
// 思路是1-》每次得到时间所需的最大值, 2-》 与资源数做比较看是否能支付 and 和K做比较,若最大值满足等于k
// 即结束,循环此操作
        int index = sunZaoMax(arr);
        while(m>=0&&arr[index][0]>k){
            //天数-1,资源-arr[index][1]
            if(m-arr[index][1]>=0){
                m-=arr[index][1];
                arr[index][0]--;
//                System.out.println("11111111111");
            }else{
                break;
            }
            index = sunZaoMax(arr);
        }
        System.out.println(arr[index][0]);
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值