# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97233 | MohamedAhmed0 | Zalmoxis (BOI18_zalmoxis) | C++14 | 350 ms | 8640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e6 + 10 ;
int freq[31] ;
vector<int>ans;
int n , k ;
void solve(int now)
{
if(now == 30)
return ;
int occ = freq[now] ;
if(occ % 2 == 0)
freq[now+1] += occ / 2 ;
else
{
ans.push_back(now) ;
--k ;
freq[now]++;
freq[now+1] += (freq[now] / 2) ;
}
solve(now + 1) ;
}
int main()
{
scanf("%d %d" , &n , &k) ;
int MIN = 31 ;
for(int i = 0 ; i < n ; ++i)
{
int x ;
scanf("%d" , &x) ;
ans.push_back(x) ;
freq[ans[i]]++;
MIN = min(MIN , ans[i]) ;
}
solve(MIN);
sort(ans.rbegin() , ans.rend()) ;
if(k > 0)
{
int x = ans.back();
ans.pop_back();
ans.push_back(x-1) ;
ans.push_back(x-1) ;
}
for(auto &i : ans)
cout<<i<<" ";
return 0 ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |