# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
103887402 |
Practice:
brunoLP |
1283D
- 14
|
C++17 (GCC 7-32)
|
Time limit exceeded on test 12
|
2000 ms
|
184976 KB
|
2021-01-09 17:21:37 |
2021-01-09 17:21:37 |
|
#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<pair<int, int>> Q;
set<int> st;
for(auto &a : A){
Q.push({a, a});
st.insert(a);
}
vector<int> ans;
int cnt = 0;
ll sum = 0;
while(cnt != M && !Q.empty()){
auto T = Q.front(); Q.pop();
if(T.fi - 1 >= LB){
if(st.find(T.fi - 1) == st.end()){
st.insert(T.fi - 1);
sum += (ll)abs((T.fi - 1) - T.se);
Q.push({T.fi - 1, T.se});
++cnt;
ans.pb(T.fi - 1);
}
}
if(T.fi + 1 <= RB){
if(st.find(T.fi + 1) == st.end()){
st.insert(T.fi + 1);
sum += (ll)abs((T.fi + 1) - T.se);
Q.push({T.fi + 1, T.se});
++cnt;
ans.pb(T.fi + 1);
}
}
}
cout << sum << ends;
for(auto &a : ans)
cout << a << sp;
cout << ends;
}
Click to see test details