//
// main.cpp
// u.cpp
//
// Created by Juri Aljohani on 30/11/2022.
//
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#define int long long
#define endl '\n'
using namespace std;
int a[1000001];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k, p = 0, cur = 0, mn = INT_MAX, j = 0; cin >> n >> k;
deque<int>ans;
for(int i = 1; i <= n; i++){
cin >> a[i];
if(a[i] == a[i - 1]) p = i;
if(a[i] < mn){
mn = a[i];
j = i;
}
}
int l = p - 2, r = p + 1;
if(p == 0){
cur = mn;
ans.push_back(mn);
ans.push_back(mn);
l = j - 1; r = j + 1;
}else{
cur = a[p];
ans.push_back(a[p]);
ans.push_back(a[p]);
}
while(l >= 0 or r <= n){
int x = cur + 1, y = cur + 2, fa = 0, fb = 0, ff = 0;
if(l >= 0 && a[l] == x){
ans.push_front(x);
l--;
fa = 1;
ff = 1;
}else if(l >= 0 && a[l] == y){
ans.push_front(y);
l--;
fb = 1;
ff = 1;
}
if(r <= n && a[r] == x){
ans.push_back(x);
r++;
fa = 1;
}else if(r <= n && a[r] == y){
ans.push_back(y);
r++;
fb = 1;
}
if(fb + fa == 0) break;
if(!fa){
if((int)ans.size() + 1 > n + k) break;
if(!ff) ans.push_front(x);
else ans.push_back(x);
}
if(!fb){
if((int)ans.size() + 1 > n + k) break;
if(!ff) ans.push_front(y);
else ans.push_back(y);
}
cur += 2;
}
while(ans.size()){
cout << ans.front() << ' ' ;
ans.pop_front();
}
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
8012 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
59 ms |
8068 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
48 ms |
8208 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
52 ms |
8060 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
47 ms |
8052 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
45 ms |
8108 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
8028 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
52 ms |
8072 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
50 ms |
8012 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
46 ms |
8116 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
53 ms |
8076 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
46 ms |
8104 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
50 ms |
8012 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
58 ms |
8152 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
38 ms |
6452 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
17 ms |
2644 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
23 ms |
4180 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |