Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <climits>
  5. using namespace std;
  6. FILE *f=fopen("turnuri2.in","r");
  7. FILE *g=fopen("turnuri2.out","w");
  8. typedef struct {int H,K;} date;
  9. date V[1000005];
  10. int st[1000005],dr[1000005],poz[1000005],i,j,N,maxim;
  11. int main()
  12. {
  13.     fscanf(f,"%d",&N);
  14.     for(i=1;i<=N;i++)
  15.         fscanf(f,"%d %d",&V[i].H,&V[i].K);
  16.     for(i=1;i<=N;i++)
  17.     {
  18.         maxim=V[i].K;
  19.         for(j=i-1;j>0&&V[j].H<=V[i].H;j=poz[j])
  20.         {
  21.             if(st[j]>maxim)
  22.                 maxim=st[j];
  23.         }
  24.         if(V[j].K>maxim)
  25.         maxim=V[j].K;
  26.         poz[i]=j;
  27.         st[i]=maxim;
  28.     }
  29.     for(i=N;i>=1;i--)
  30.     {
  31.         maxim=V[i].K;
  32.         for(j=i+1;j<=N&&V[j].H<=V[i].H;j=poz[j])
  33.         {
  34.             if(dr[j]>maxim)
  35.                 maxim=dr[j];
  36.         }
  37.         if(V[j].K>maxim)
  38.         maxim=V[j].K;
  39.         poz[i]=j;
  40.         dr[i]=maxim;
  41.     }
  42.     for(i=1;i<=N;i++)
  43.         fprintf(g,"%d\n",max(dr[i],st[i]));
  44.     fclose(f);
  45.     fclose(g);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement