编程语言:Java
题目链接:http://poj.org/problem?id=2393
题解:很简单的一道题,用变量存取上一周的酸奶成本,这样就可以边输入边进行成本运算了。注意:存储总成本的变量需要声明为long型,不然会WA的。
结果:AC
import java.io.*;
import java.util.Scanner;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) throws IOException {
int n=sc.nextInt();
int s=sc.nextInt();
int last=sc.nextInt();
int num=sc.nextInt();
long res=last*num;
for(int i=1;i<n;i++){
last=Math.min(last+s,sc.nextInt());
num=sc.nextInt();
res+=last*num;
}
out.println(res);
out.flush();
}
}