Advertisement
Guest User

E

a guest
Sep 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.io.PrintWriter;
  8. import java.util.Collections;
  9. import java.util.PriorityQueue;
  10. import java.util.Random;
  11. import java.util.StringTokenizer;
  12.  
  13. public class D {
  14.    
  15.     public static void main(String[] args) {
  16.         FastReader scan = new FastReader();
  17.         PrintWriter out = new PrintWriter(System.out);
  18.         Task solver = new Task();
  19.         int t = 1;
  20.         while(t-->0) solver.solve(1, scan, out);
  21.         out.close();
  22.     }
  23.    
  24.     static class Task {
  25.        
  26.         public void solve(int testNumber, FastReader scan, PrintWriter out) {
  27.             long total = 0;
  28.             int n = scan.nextInt(), m = scan.nextInt();
  29.             PriorityQueue<Long> q = new PriorityQueue<>(Collections.reverseOrder());
  30.             for(int i = 0; i < n; i++) q.add(scan.nextLong());
  31.             for(int i = 0; i < m; i++) {
  32.                 long g = q.poll();
  33.                 q.add(g/2);
  34.             }
  35.             for(long x : q) total += x;
  36.             out.println(total);
  37.         }
  38.     }
  39.    
  40.     static void shuffle(int[] a) {
  41.         Random get = new Random();
  42.         for(int i = 0; i < a.length; i++) {
  43.             int r = get.nextInt(a.length);
  44.             int temp = a[i];
  45.             a[i] = a[r];
  46.             a[r] = temp;
  47.         }
  48.     }
  49.    
  50.     static void shuffle(long[] a) {
  51.         Random get = new Random();
  52.         for(int i = 0; i < a.length; i++) {
  53.             int r = get.nextInt(a.length);
  54.             long temp = a[i];
  55.             a[i] = a[r];
  56.             a[r] = temp;
  57.         }
  58.     }
  59.    
  60.  
  61.     static class FastReader {
  62.         BufferedReader br;
  63.         StringTokenizer st;
  64.  
  65.         public FastReader() {
  66.             br = new BufferedReader(new InputStreamReader(System.in));
  67.         }
  68.         public FastReader(String s) throws FileNotFoundException {
  69.             br = new BufferedReader(new FileReader(new File(s)));
  70.         }
  71.  
  72.         String next() {
  73.             while (st == null || !st.hasMoreElements()) {
  74.                 try {
  75.                     st = new StringTokenizer(br.readLine());
  76.                 } catch (IOException e) {
  77.                     e.printStackTrace();
  78.                 }
  79.             }
  80.             return st.nextToken();
  81.         }
  82.  
  83.         int nextInt() {
  84.             return Integer.parseInt(next());
  85.         }
  86.  
  87.         long nextLong() {
  88.             return Long.parseLong(next());
  89.         }
  90.  
  91.         double nextDouble() {
  92.             return Double.parseDouble(next());
  93.         }
  94.  
  95.         String nextLine() {
  96.             String str = "";
  97.             try {
  98.                 str = br.readLine();
  99.             } catch (IOException e) {
  100.                 e.printStackTrace();
  101.             }
  102.             return str;
  103.         }
  104.     }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement