-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaaaaaaaaaaaa
More file actions
65 lines (55 loc) · 1.06 KB
/
Copy pathaaaaaaaaaaaa
File metadata and controls
65 lines (55 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package nine;
import java.util.Arrays;
import java.util.Scanner;
public class First
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
while(cin.hasNext())
{
int n = cin.nextInt();
int m = cin.nextInt();
int[] as = new int[n];
for(int i = 0; i < n; i++)
as[i] = cin.nextInt();
int[] bs = new int[m];
int[] cs = new int[m];
for(int i = 0; i < m; i++)
{
bs[i] = cin.nextInt();
cs[i] = cin.nextInt();
}
boolean[] vis = new boolean[m];
Arrays.sort(as);
Arrays.fill(vis, false);
int sum = 0;
for(int i = 0; i < as.length; i++)
{
int idx = getMaxIdx(bs, cs, vis, as[i]);
if(idx == -1)
continue;
vis[idx] = true;
sum += cs[idx];
}
System.out.println(sum);
}
cin.close();
}
private static int getMaxIdx(int[] bs, int[] cs, boolean[] vis, int a)
{
int idx = -1;
int max = -1;
for(int i = 0; i < bs.length; i++)
{
if(bs[i]>a || vis[i])
continue;
if(max < cs[i])
{
max = cs[i];
idx = i;
}
}
return idx;
}
}