This repository was archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmilk.java
More file actions
53 lines (51 loc) · 1.52 KB
/
milk.java
File metadata and controls
53 lines (51 loc) · 1.52 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
48
49
50
51
52
53
/*
TASK:milk
ID:JOHNATH6
LANG:JAVA
PROB:milk
*/
import java.io.*;
import java.util.*;
public class milk {
public static void main(String[] args) throws IOException{
BufferedReader f=new BufferedReader(new FileReader("milk.in"));
StringTokenizer st=new StringTokenizer(f.readLine());
int full=Integer.parseInt(st.nextToken());
int N=Integer.parseInt(st.nextToken());
int[] arr=new int[1001];
int totalprice=0;
int cur=0;
int n;
int k,r;
for(int i=0;i<N;i++) {
st=new StringTokenizer(f.readLine());
k=Integer.parseInt(st.nextToken());
r=Integer.parseInt(st.nextToken());;
if(arr[k]==0) {arr[k]=r;}else {arr[k]=arr[k]+r;}
}
f.close();
System.out.println("GRAPH-----------------------------");
System.out.println("----------------------------------");
System.out.println("Amount Price ");
for(int i=0;i<1001;i++) {
//System.out.println("Buying price "+i);
if(cur==full) {
//System.out.println("Full capactiy");
break;
}
if(arr[i]==0) {
//System.out.println("?");
continue;
}
if((full-cur)>=arr[i]) {totalprice+=(arr[i]*i);cur+=(arr[i]);System.out.println(""+arr[i]+" "+i+" "+totalprice+" "+cur);}else {
n=full-cur;
totalprice+=(n*i);cur+=(n);
System.out.println(""+n+" "+i+" "+totalprice+" "+cur);
}
}
PrintWriter pw=new PrintWriter(new FileWriter("milk.out"));
System.out.println(totalprice);
pw.println(totalprice);
pw.close();
}
}