import java.util.Arrays;
import java.util.Scanner;
//餐馆
public class Main_833 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int desk = sc.nextInt();
int pic = sc.nextInt();
int[] ml = new int[desk];
for (int i = 0; i < desk; i++) {
ml[i] = sc.nextInt();
}
Arrays.sort(ml);
int[] man = new int[pic];
int[] rmb = new int[pic];
int[] rmbSort = new int[pic];
for (int i = 0; i < pic; i++) {
man[i] = sc.nextInt();
rmb[i] = sc.nextInt();
rmbSort[i] = rmb[i];
}
Arrays.sort(rmbSort);
int value = 0;
int i = rmb.length - 1;
int count = ml.length;
while (true) {
for (int j = 0; j < pic; j++) {
if (i >= 0 && rmb[j] == rmbSort[i]) {
for (int k = 0; k < desk; k++) {
if (man[j] <= ml[k]) {
value += rmb[j];
ml[k] = 0;
count--;
if (count == 0 || i == 0) {
System.out.println(value);
break;
}
break;
}
}
i--;
}
}
if (value == 0) {
System.out.println(0);
break;
}
}
}
sc.close();
}
}
//3 5 2 4 2 1 3 3 5 3 7 5 9 1 10
//4 6 12 1 4 7 11 3 3 10 35 10 5 9 12 10 6 7
//import java.util.*;
//
//public class Main_833 {
// public static void main(String[] args) {
// Scanner scanner = new Scanner(System.in);
// while (scanner.hasNext()) {
// int size = scanner.nextInt();
// int batch = scanner.nextInt();
// int[] desk = new int[size];
// for (int i = 0; i < size; i++) {
// desk[i] = scanner.nextInt();
// }
// Arrays.sort(desk);
// PriorityQueue<Person> queue = new PriorityQueue<>();
// for (int j = 0; j < batch; j++) {
// int num = scanner.nextInt();
// int money = scanner.nextInt();
// if (num <= desk[size - 1]) {
// queue.add(new Person(num, money));
// }
// }
// boolean[] tag = new boolean[size];
// long sum = 0;
// int count = 0;
// while (!queue.isEmpty()) {
// Person p = queue.poll();
// for (int i = 0; i < size; i++) {
// if (p.num <= desk[i] && !tag[i]) {
// sum += p.money;
// count++;
// tag[i] = true;
// break;
// }
// }
// if (count == size) {
// break;
// }
// }
// System.out.println(sum);
// }
// }
//
// static class Person implements Comparable<Person> {
// private int num;
// private int money;
//
// public Person(int num, int money) {
// this.num = num;
// this.money = money;
// }
//
// public int compareTo(Person o) {
// if (this.money > o.money) {
// return -1;
// } else if (this.money < o.money) {
// return 1;
// } else {
// return 0;
// }
// }
// }
//}
//餐馆
猜你喜欢
转载自blog.csdn.net/TIANHE_/article/details/107774116
今日推荐
周排行