#include <bits/stdc++.h> #define _2137 0 #define pb push_back #define ff first #define ss second using namespace std; unsigned long long ans[3000007]; vector <int> tab[1000001]; void count(int which){ int size=tab[which].size() , beg=(size-1)/2; if(size&1){ ++ans[size + tab[which][beg]*2]; } else{ ++ans[size + tab[which][beg]+tab[which][beg+1]]; } } int main() { int n; scanf("%d",&n); int num; scanf("%d",&num); /* if(n==1){ printf("%d 1",1+num*2); return _2137; } */ tab[0].pb(num); ++ans[num*2+1]; for(int i=2;i<=n;++i){ scanf("%d",&num); for(int j=0;j<i;++j){ tab[j].insert(upper_bound(tab[j].begin(),tab[j].end(),num),num); count(j); } } int i=n*3+1; while(ans[i]==0){ --i; } printf("%d %d",i,ans[i]); return _2137; }
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 62 63 64 65 66 67 68 69 70 71 | #include <bits/stdc++.h> #define _2137 0 #define pb push_back #define ff first #define ss second using namespace std; unsigned long long ans[3000007]; vector <int> tab[1000001]; void count(int which){ int size=tab[which].size() , beg=(size-1)/2; if(size&1){ ++ans[size + tab[which][beg]*2]; } else{ ++ans[size + tab[which][beg]+tab[which][beg+1]]; } } int main() { int n; scanf("%d",&n); int num; scanf("%d",&num); /* if(n==1){ printf("%d 1",1+num*2); return _2137; } */ tab[0].pb(num); ++ans[num*2+1]; for(int i=2;i<=n;++i){ scanf("%d",&num); for(int j=0;j<i;++j){ tab[j].insert(upper_bound(tab[j].begin(),tab[j].end(),num),num); count(j); } } int i=n*3+1; while(ans[i]==0){ --i; } printf("%d %d",i,ans[i]); return _2137; } |