This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int niz[1000001];
int n;
int k;
int vis[1000001];
using pii = pair<int,pair<int,int>>;
int main()
{
cin >> n >> k;
priority_queue<pii, vector<pii> , greater<pii> > pq;
for(int i = 0; i < n; i++){
cin >> niz[i];
pq.push({niz[i],{i,i}});
}
int ans = -1;
int ind = -1;
int t1 = 0;
while(!pq.empty() and t1 == 0){
pii a = pq.top();
pq.pop();
if(pq.empty()){
ans = a.first;
ind = a.second.second;
t1++;
break;
}else{
pii b = pq.top();
pq.pop();
if(a.first != b.first){
ans = a.first;
ind = a.second.second;
t1++;
break;
}else{
int prvi = a.second.second + 1;
int drugi = b.second.first;
if(prvi == drugi){
pq.push({a.first + 1,{a.second.first,b.second.second}});
}else{
ans = a.first;
ind = a.second.second;
t1++;
break;
}
}
}
}
for(int i = 0; i < n; i++){
cout << niz[i] << " ";
if(ind == i){
cout << ans << " ";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |