-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.cpp
More file actions
38 lines (33 loc) · 722 Bytes
/
sort.cpp
File metadata and controls
38 lines (33 loc) · 722 Bytes
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
#include <iostream>
#include <algorithm>
using namespace std;
struct cowinput{
int num;
int pos;
};
bool cowsnewcomp(cowinput a, cowinput b){
return a.num<b.num;
}
int main(){
int n, maxx=-1;
cin >> n;
cowinput cowsog[n], cowsnew[n];
for(int i=0; i<n; i++){
cin >> cowsog[i].num;
cowsnew[i].num=cowsog[i].num;
cowsog[i].pos=i;
cowsnew[i].pos=i;
}
sort(cowsnew, cowsnew+n, cowsnewcomp);
for(int i=0; i<n; i++){
if(cowsnew[i].pos-cowsog[i].pos>maxx){
maxx=cowsnew[i].pos-cowsog[i].pos+1;
}
}
if(maxx>5000){
cout << maxx << endl;
return 0;
}
cout << maxx << endl;
return 0;
}