#include <bits/stdc++.h>
using namespace std;
int main() {
int a,i,j,h,g,n,w,l,z;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
j=1;
h=1;
l=0;
z=2;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>a;
vector <int> t((n*(n+1))/2);
vector <int> d(2021);
vector <int> x(n);
for(i=1; i<(((n*(n+1))/2)+1);i++) {
cin>>g;
t[i]=g;
x[i]=j;
if(h==j) {
j++;
h=0;
}
h++;
if(d[t[i]]==0) d[t[i]]=i;
}
sort(t.begin(),t.end());
i=1;
while(1) {
if(x[d[t[i]]]!=x[d[t[i]]+1]) {
if(x[d[t[i]]]<=n) {
w=t[i];
break;
}
}
else{
if(x[d[t[i]]]>x[d[t[i]]-x[d[t[i]]]]) {
d[t[i]]=d[t[i]]-x[d[t[i]]];
l+=z;
z++;
}
else {
d[t[i]]=d[t[i]]-x[d[t[i]]]+1;
l+=z;
z++;
}
}
if(l>n) i++;
}
cout<<w;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <bits/stdc++.h> using namespace std; int main() { int a,i,j,h,g,n,w,l,z; ios_base::sync_with_stdio(false); cin.tie(NULL); j=1; h=1; l=0; z=2; ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>a; vector <int> t((n*(n+1))/2); vector <int> d(2021); vector <int> x(n); for(i=1; i<(((n*(n+1))/2)+1);i++) { cin>>g; t[i]=g; x[i]=j; if(h==j) { j++; h=0; } h++; if(d[t[i]]==0) d[t[i]]=i; } sort(t.begin(),t.end()); i=1; while(1) { if(x[d[t[i]]]!=x[d[t[i]]+1]) { if(x[d[t[i]]]<=n) { w=t[i]; break; } } else{ if(x[d[t[i]]]>x[d[t[i]]-x[d[t[i]]]]) { d[t[i]]=d[t[i]]-x[d[t[i]]]; l+=z; z++; } else { d[t[i]]=d[t[i]]-x[d[t[i]]]+1; l+=z; z++; } } if(l>n) i++; } cout<<w; return 0; } |
English