Guest User

Untitled

a guest
May 20th, 2017
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.beans.Customizer;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.ArrayList;
  6. import java.util.Collections;
  7. import java.util.List;
  8. import java.util.StringTokenizer;
  9.  
  10. public class CF415B {
  11. static class Day implements Comparable<Day> {
  12.  
  13. int idx;
  14. int products;
  15.  
  16. @Override
  17. public int compareTo(Day arg0) {
  18. return products - arg0.products;
  19. }
  20.  
  21. public Day(int idx, int products) {
  22. this.idx = idx;
  23. this.products = products;
  24. }
  25.  
  26. }
  27.  
  28. public static void main(String[] args) {
  29. MyScanner reader = new MyScanner();
  30. StringBuilder sb = new StringBuilder();
  31. // int a = reader.nextInt();
  32. // int b = reader.nextInt();
  33.  
  34. int n = reader.nextInt();
  35. int f = reader.nextInt();
  36.  
  37. List<Day> arr = new ArrayList<>();
  38. int[] customers = new int[n];
  39. int[] products = new int[n];
  40. for (int i = 0; i < n; i++) {
  41. products[i] = reader.nextInt();
  42. customers[i] = reader.nextInt();
  43. if (customers[i] <= 2 * products[i]) {
  44. arr.add(new Day(i, customers[i]));
  45. } else {
  46. arr.add(new Day(i, 2 * products[i]));
  47. }
  48.  
  49. }
  50.  
  51. long sum = 0;
  52. Collections.sort(arr);
  53. boolean[] used = new boolean[n];
  54. // System.out.println(arr);
  55. for (int i = arr.size() - 1; i >= arr.size() - f; i--) {
  56. sum += arr.get(i).products;
  57. used[arr.get(i).idx] = true;
  58. }
  59. for (int i = 0; i < used.length; i++) {
  60. if (used[i] == false) {
  61. if (customers[i] <= products[i]) {
  62. sum += customers[i];
  63. } else {
  64. sum += products[i];
  65. }
  66. }
  67. }
  68. System.out.println(sum);
  69. }
  70.  
  71. public static class MyScanner {
  72. BufferedReader br;
  73. StringTokenizer st;
  74.  
  75. public MyScanner() {
  76. br = new BufferedReader(new InputStreamReader(System.in));
  77. }
  78.  
  79. String next() {
  80. while (st == null || !st.hasMoreElements()) {
  81. try {
  82. st = new StringTokenizer(br.readLine());
  83. } catch (IOException e) {
  84. e.printStackTrace();
  85. }
  86. }
  87. return st.nextToken();
  88. }
  89.  
  90. int nextInt() {
  91. return Integer.parseInt(next());
  92. }
  93. }
  94.  
  95. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×