-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownload.java
56 lines (52 loc) · 1.18 KB
/
Download.java
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
48
49
50
51
52
53
54
55
56
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author Vishal
*/
class Download {
public static void main(String arg[])
{
Scanner sc = new Scanner(System.in);
long t = sc.nextLong();
for(long i = 1; i <= t; i++)
{
long n = sc.nextLong();
long k = sc.nextLong();
long sum = 0;
boolean free = true;
for(long j = 1; j <= n; j++)
{
long T = sc.nextLong();
long D = sc.nextLong();
if(free == true)
{
if(T < k)
{
k = k - T;
}
else if(T > k)
{
T = T - k;
k = 0;
}
else
{
k = 0;
continue;
}
}
if(k == 0)
{
free = false;
sum += T * D;
}
}
System.out.println(sum);
}
}
}