Submission #7531473


Source Code Expand

Copy
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> struct Heap_max{
  int size;
  T *val;
  void malloc(const int N){
    val = (T*) std::malloc(N*sizeof(T));
    size = 0;
  }
  void walloc(const int N, void **mem = &wmem){
    walloc1d(&val, N, mem);
    size = 0;
  }
  void free(){
    std::free(val);
  }
  void init(){
    size = 0;
  }
  void up(){
    int n = size - 1;
    int m;
    while(n){
      m = (n-1) / 2;
      if(val[m] >= val[n]){
        break;
      }
      swap(val[m], val[n]);
      n = m;
    }
  }
  void down(){
    int n = 0;
    int m;
    for(;;){
      m=2*n+1;
      if(m>=size){
        break;
      }
      if(m+1<size && val[m] < val[m+1]){
        m++;
      }
      if(val[m] <= val[n]){
        break;
      }
      swap(val[m], val[n]);
      n=m;
    }
  }
  T top(){
    return val[0];
  }
  T pop(){
    T res = val[0];
    size--;
    if(size > 0){
      val[0] = val[size];
      down();
    }
    return res;
  }
  T push(const T x){
    val[size++] = x;
    up();
    return x;
  }
}
;
int N;
int M;
int A[100000];
int main(){
  int KL2GvlyY, i;
  wmem = memarr;
  int tmp;
  long long res = 0;
  Heap_max<int> h;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  h.malloc(N);
  for(i=0;i<(N);i++){
    h.push(A[i]);
  }
  for(KL2GvlyY=0;KL2GvlyY<(M);KL2GvlyY++){
    tmp = h.pop();
    h.push(tmp/2);
  }
  while(h.size){
    res += h.pop();
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190914-1

// --- original code ---
// int N, M, A[1d5];
// {
//   int tmp;
//   ll res = 0;
//   Heap_max<int> h;
//   rd(N,M,A(N));
//   h.malloc(N);
//   rep(i,N) h.push(A[i]);
//   rep(M){
//     tmp = h.pop();
//     h.push(tmp/2);
//   }
//   while(h.size) res += h.pop();
//   wt(res);
// }

Submission Info

Submission Time
Task D - Powerful Discount Tickets
User LayCurse
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2821 Byte
Status AC
Exec Time 24 ms
Memory 1024 KB

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 23
AC × 4
Set Name Test Cases
All sample_01, sample_02, sample_03, sample_04, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19
Sample sample_01, sample_02, sample_03, sample_04
Case Name Status Exec Time Memory
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 1 ms 256 KB
sample_04 AC 1 ms 256 KB
testcase_01 AC 10 ms 768 KB
testcase_02 AC 10 ms 256 KB
testcase_03 AC 16 ms 1024 KB
testcase_04 AC 24 ms 1024 KB
testcase_05 AC 7 ms 640 KB
testcase_06 AC 18 ms 896 KB
testcase_07 AC 4 ms 384 KB
testcase_08 AC 15 ms 1024 KB
testcase_09 AC 17 ms 768 KB
testcase_10 AC 7 ms 384 KB
testcase_11 AC 15 ms 768 KB
testcase_12 AC 24 ms 1024 KB
testcase_13 AC 8 ms 256 KB
testcase_14 AC 10 ms 1024 KB
testcase_15 AC 24 ms 1024 KB
testcase_16 AC 11 ms 384 KB
testcase_17 AC 1 ms 256 KB
testcase_18 AC 1 ms 256 KB
testcase_19 AC 4 ms 1024 KB