/*
Editor: Abdelrahman Hossam
Nickname: Blobo2_Blobo2
IOI next year isA :)
*/
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int16_t
#define endl "\n"
#define all(v) v.begin(),v.end()
#define gen(arr,n,nxt) generate(arr,arr+n,nxt)
#define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0);
#define EPS 0.00000001
const int mo=1e9+7,INF=1e18;
int nxt(){int x;cin>>x;return x;}
signed main(){
Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty
int n=nxt(),k=nxt();
vector<int>v;
int zeroes = 0;
for(int i=0;i<n;i++){
int x = nxt();
v.push_back(x);
if(!x)
zeroes ++;
}
sort(all(v));
if(n - zeroes < k)cout<<-1;
else if(zeroes == n && k == 0){
for(int i=0;i<n;i++)cout<<0<<' ';
return 0;
}
else(k==0){
cout<<-1<<endl;
return 0;
}
else{
vector<int>ans;
int idx =0;
for(int i = n-1,j = 0;i>=0&&j<k;i--,j++)
ans.push_back(v[i]),idx = i;
reverse(all(ans));
for(int i=0;i<idx;i++)
ans.push_back(v[i]);
int cnt=0;
int ok=0;
for(int i=0;i<n;i++){
if(cnt < ans[i]){
cnt++;
ok++;
}
}
if(ok!=k)cout<<-1<<endl;
else{
reverse(all(ans));
for(auto x:ans)cout<<x<<' ';
}
}
return 0;
}
Compilation message
karte.cpp: In function 'int main()':
karte.cpp:42:15: error: expected ';' before '{' token
42 | else(k==0){
| ^
| ;
karte.cpp:46:5: error: 'else' without a previous 'if'
46 | else{
| ^~~~