- 徒步
public static void main(String[]args){
Scanner in=new Scanner(System.in);
int days=in.nextInt();
int nums=in.nextInt();
int [][]food=new int[nums][2];
in.nextLine();
for(int i=0;i<nums;i++){
food[i][0]=in.nextInt();
food[i][1]=in.nextInt();
}
int res = 0;
int min = Integer.MAX_VALUE;
int cur = days;
while (nums > 0) {
if (food[nums - 1][1] < min && nums >= 1) min = food[nums - 1][1];
else {
res += (cur - food[nums][0]) * min;
min = Integer.MAX_VALUE;
cur = food[nums][0];
}
if (nums == 1) {
res += (cur - food[0][0]) * food[0][1];
}
nums--;
}
System.out.println(res);
}
- 如何公平分土地
- 字符串大小写变换