Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int NMAX = 100000;
- int p, N;
- int v[NMAX];
- long long produs(int v[NMAX]){
- long long prod = 0;
- prod = v[N] * v[1];
- for(int i = 1; i <= N - 1; i++)
- prod = prod + v[i] * v[i+1];
- return prod;
- }
- int main(){
- freopen("roboti3.in", "r", stdin);
- freopen("roboti3.out", "w", stdout);
- scanf("%d%d", &p, &N);
- for(int i = 1; i <= N; i++)
- scanf("%d", &v[i]);
- if(p == 1){
- int scmax = 0, val = 1;
- int cresc[NMAX];
- cresc[1] = 1;
- for(int i = 2; i <= N; i++){
- if(v[i] > v[i-1])
- cresc[i] = cresc[i-1] + 1;
- else{
- val++;
- cresc[i] = 1;
- }
- if(cresc[i] > scmax)
- scmax = cresc[i];
- }
- if(v[N] < v[1]){
- cresc[1] = cresc[N] + 1;
- int i = 2;
- while(v[i] > v[i-1]){
- cresc[i] = cresc[i-1] + 1;
- i++;
- }
- if(cresc[i-1] > scmax)
- scmax = cresc[i-1];
- }
- printf("%d", scmax);
- } else {
- int pmax[NMAX], cnt[NMAX/100], af[NMAX/100];
- int i, mns = 0;
- sort(v+1, v+N+1);
- /*for(i = 1; i <= N; i++)
- printf("%d ", v[i]);
- printf("\n\n");*/
- for(i = 1; i <= N / 2; i++)
- pmax[i] = v[2*i];
- for(int j = N % 2; j <= N - N / 2; j++, i++)
- pmax[i] = v[N - 2 * j - 1 + N % 2];
- for(i = 1; i <= N; i++)
- printf("%d ", pmax[i]);
- for(i = N / 2 + 1 - N % 2; i <= N; i++){
- cnt[pmax[i]]++;
- if(cnt[pmax[i]] > 1)
- af[i] = 1;
- }
- if(pmax[N] == pmax[1]){
- printf("%d ", pmax[1]);
- mns = 1;
- }
- for(int i = 1; i <= N - mns; i++){
- if(!af[i])
- printf("%d ", pmax[i]);
- while(cnt[pmax[i]] > 1){
- printf("%d ", pmax[i]);
- cnt[pmax[i]]--;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement