-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadFile.java
More file actions
47 lines (34 loc) · 1.06 KB
/
DownloadFile.java
File metadata and controls
47 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package problems.codechef;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by hardCode on 2/19/2017.
*/
public class DownloadFile {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int tc,n,k,timeSum,ans;
String[]s;
tc = Integer.parseInt(br.readLine());
while (tc-->0){
ans=0;
timeSum=0;
s=br.readLine().split("\\s");
n=Integer.parseInt(s[0]);
k=Integer.parseInt(s[1]);
for (int i = 0; i < n; i++) {
s=br.readLine().split("\\s");
int t=Integer.parseInt(s[0]);
int d=Integer.parseInt(s[1]);
if (timeSum==k)ans+=t*d;
else if (timeSum+t>k){
ans+=(t-(k-timeSum))*d;
timeSum=k;
}
else timeSum+=t;
}
System.out.println(ans);
}
}
}