Advertisement
Guest User

amplifiers.c

a guest
Jul 19th, 2010
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include"stdio.h"
  2. #include"tubgirl.h"
  3.  
  4. FILE *io;
  5.  
  6. int n;
  7.  
  8. int stack[200001];
  9. int sp=0;
  10.  
  11. long long amps=0;
  12.  
  13. int main(){
  14.     int i,j,k,e,d;
  15.     io=fopen("amplifiers.in","r");
  16.    
  17.     fscanf(io,"%d",&n);
  18.     fscanf(io,"%d",stack);
  19.    
  20.     for(i=1;i<n;i++){
  21.         fscanf(io,"%d",&e);
  22.         //printf("Bhma %d\n",e);
  23.         if(e>=stack[0]){
  24.             //printf("NEO PEKOP!!!\n");
  25.             amps+=e-stack[sp];
  26.             stack[0]=e;
  27.             sp=0;
  28.         }
  29.         else if(e<stack[sp]){
  30.             //printf("OLO K PIO KATW\n");
  31.             sp++;
  32.             stack[sp]=e;
  33.         }else{
  34.             //printf("ANABAINOMEN\n");
  35.             amps+=e-stack[sp];
  36.             for(;stack[sp]<=e;sp--);
  37.             sp++;
  38.             stack[sp]=e;
  39.         }
  40.     }
  41.     amps+=stack[0]-stack[sp];
  42.    
  43.     freopen("amplifiers.out","w",io);
  44.     fprintf(io,"%d\n",amps);
  45.     printf("%d\n",amps);
  46.     fclose(io);
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement