This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;
typedef long long ll;
typedef pair < int , int > ii;
int n, k, m, a[N], b[N];
ii ans;
set < ii > s, q;
set < ii > :: iterator it;
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d %d",&n ,&k);
for(int i = 1; i <= n; i++){
scanf("%d",a + i);
q.insert(mp(a[i], i));
s.insert(mp(i, a[i]));
}
while(!q.empty()){
int kac = q.begin()->st;
if(kac == 30)
break;
int ind = q.begin()->nd;
// cout << kac << " " << ind << endl;
it = s.find(mp(ind, kac));
it++;
if(it != s.end() and it->nd == kac){
int ind2 = it->st;
// cout << "BULDUM " << ind << " " << ind2 << endl;
s.erase(mp(ind, kac));
s.erase(mp(ind2, kac));
s.insert(mp(ind2, kac + 1));
q.erase(mp(kac, ind));
q.erase(mp(kac, ind2));
q.insert(mp(kac + 1, ind2));
} else{
// cout << ind << " den sonra " << kac << " ekle" << endl;
ans = mp(ind, kac);
s.erase(mp(ind, kac));
s.insert(mp(ind, kac + 1));
q.erase(mp(kac, ind));
q.insert(mp(kac + 1, ind));
}
}
for(int i = 1; i <= n; i++){
printf("%d ", a[i]);
if(i == ans.st)
printf("%d ", ans.nd);
}
return 0;
}
Compilation message (stderr)
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n ,&k);
~~~~~^~~~~~~~~~~~~~~~
zalmoxis.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",a + i);
~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |