Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- TaskTen solution = new TaskTen();
- solution.solve();
- }
- static class TaskTen {
- private Scanner sc = new Scanner(System.in);
- private int money = 0;
- private List<Integer> power = new ArrayList<>();
- private List<Pair> info = new ArrayList<>();
- private static class Pair {
- int first;
- int second;
- Pair(int first, int second) {
- this.first = first;
- this.second = second;
- }
- }
- public void solve() {
- readInput();
- info.sort(Comparator.comparingInt(t -> t.second));
- power.sort(Comparator.reverseOrder());
- for(Pair pair : info){
- getOptimal(pair);
- }
- System.out.println(money);
- }
- private void getOptimal(Pair conditioner){
- for(int i : power){
- if(i <= conditioner.first){
- money += conditioner.second;
- power.remove((Integer) i);
- return;
- }
- }
- }
- private void readInput() {
- int n = sc.nextInt();
- for (int i = 0; i < n; i++) {
- power.add(sc.nextInt());
- }
- int r = sc.nextInt();
- for (int i = 0; i < r; i++) {
- info.add(new Pair(sc.nextInt(), sc.nextInt()));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement