CSES - Datatähti 2017 loppu - Results
Submission details
Task:Mex-luku
Sender:Senpai
Submission time:2017-01-19 17:14:49 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:34:1: error: 'else' without a previous 'if'
 else{
 ^
input/code.cpp:38:5: error: 'i' was not declared in this scope
 d=v[i-k+1];
     ^
input/code.cpp: At global scope:
input/code.cpp:44:1: error: expected declaration before '}' token
 }
 ^

Code

#include <bits/stdc++.h>
using namespace std;
long long n,k,x,d,e,h;
vector<int>v;
multiset<int>s;
multiset<int>t;
int main(){
cin>>n>>k;
for(int i=0; i<k-1; i++){
cin>>x;
v.push_back(x);
t.insert(x);
}

for(int i=k-1; i<n; i++){
cin>>x;
v.push_back(x);
t.insert(x);
auto it=t.begin();
auto ti=t.begin();
auto ku=t.end();
ku--;
ti++;
if(t.count(0)==0) cout<<0<<" ";
else{
while(abs(*it-*ti)==1){

it++;
ti++;

}
}

else{
e=*it;
cout<<e+1<<" ";}
}
d=v[i-k+1];
t.erase(t.find(d));
h=0;

}

}