#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
os << '{';
for(int i=0;i<sz(a);i++)
{
if(i>0&&i<sz(a)-1)
os << ", ";
os << a[i];
}
os << '}';
return os;
}
int cnt;
void razlozi(int n)
{
if(cnt>1)
{
cnt--;
razlozi(n-1);
}
else
{
printf("%i ",n);
}
printf("%i ",n);
}
int main()
{
int n,k;
scanf("%i %i",&n,&k);
vector<vector<int> > res(n);
priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>> >,greater<pair<int,pair<int,int> > > > poz;
for(int i=0;i<n;i++)
{
int a;
scanf("%i",&a);
res[i].pb(a);
poz.push({a,{i,i}});
}
while((poz.top()).first!=30)
{
pair<int,pair<int,int> > b=poz.top();
poz.pop();
if(poz.size()==0)
{
k--;
res[b.second.second].pb(b.first);
poz.push({b.first+1,b.second});
continue;
}
pair<int,pair<int,int> > sl=poz.top();
//cout << b << sl << "\n";
if(b.first==sl.first&&sl.second.first-1<=b.second.second)
{
poz.pop();
poz.push({b.first+1,{b.second.first,max(b.second.second,sl.second.second)}});
//cout << "mergujem " << b << sl << "\n";
}
else
{
k--;
res[b.second.second].pb(b.first);
poz.push({b.first+1,b.second});
}
}
vector<vector<int> > razlozen(n);
for(int i=0;i<n;i++)
{
razlozen[i].resize(res[i].size());
for(int j=1;j<(int)res[i].size();j++)
{
int po=pow(2,res[i][j]);
razlozen[i][j]=min(po,k);
k-=min(po,k);
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<(int)res[i].size();j++)
{
if(razlozen[i][j])
{
cnt=razlozen[i][j];
razlozi(res[i][j]-1);
}
else
{
printf("%i ",res[i][j]);
}
}
}
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i",&n,&k);
~~~~~^~~~~~~~~~~~~~~
zalmoxis.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&a);
~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
806 ms |
125932 KB |
Output is correct |
2 |
Correct |
886 ms |
127940 KB |
Output is correct |
3 |
Correct |
821 ms |
130152 KB |
Output is correct |
4 |
Correct |
815 ms |
132244 KB |
Output is correct |
5 |
Correct |
837 ms |
134236 KB |
Output is correct |
6 |
Correct |
813 ms |
136180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
829 ms |
138304 KB |
Output is correct |
2 |
Correct |
863 ms |
140300 KB |
Output is correct |
3 |
Correct |
831 ms |
142144 KB |
Output is correct |
4 |
Correct |
838 ms |
144516 KB |
Output is correct |
5 |
Correct |
819 ms |
146584 KB |
Output is correct |
6 |
Correct |
809 ms |
148676 KB |
Output is correct |
7 |
Correct |
826 ms |
150784 KB |
Output is correct |
8 |
Correct |
857 ms |
152896 KB |
Output is correct |
9 |
Correct |
834 ms |
152896 KB |
Output is correct |
10 |
Correct |
394 ms |
152896 KB |
Output is correct |
11 |
Correct |
567 ms |
152896 KB |
Output is correct |
12 |
Correct |
105 ms |
152896 KB |
Output is correct |
13 |
Correct |
106 ms |
152896 KB |
Output is correct |
14 |
Correct |
134 ms |
152896 KB |
Output is correct |