# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
103885753 |
Practice:
brunoLP |
1283D
- 14
|
C++17 (GCC 7-32)
|
Accepted
|
452 ms
|
15932 KB
|
2021-01-09 17:02:10 |
2021-01-09 17:02:10 |
|
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
#define sz(x) ((int)(x).size())
#define pb push_back
#define vt vector
#define arr array
#define fi first
#define se second
#define ends "\n"
#define sp ' '
#define fun function
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long MOD=1e9+7;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
const int LB = -2e9, RB = 2e9;
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
int N, M; cin >> N >> M;
vector<int> A(N); for(auto &a : A) cin >> a;
queue<int> Q;
//set<int> st;
map<int, int> mp;
for(auto &a : A){
Q.push(a);
mp[a] = 0;
}
vector<int> ans;
int cnt = 0;
ll sum = 0;
while(cnt != M && !Q.empty()){
auto T = Q.front(); Q.pop();
if(T - 1 >= LB){
if(!mp.count(T - 1)){
mp[T - 1] = mp[T] + 1;
sum += (ll)mp[T-1];
Q.push({T - 1});
ans.pb(T - 1);
++cnt;
}
}
if(T - 1 <= RB && cnt != M){
if(!mp.count(T + 1)){
mp[T + 1] = mp[T] + 1;
sum += (ll)mp[T + 1];
Q.push({T + 1});
ans.pb(T + 1);
++cnt;
}
}
// dbg(T, sum);
}
cout << sum << ends;
for(auto &a : ans)
cout << a << sp;
cout << ends;
}
Click to see test details