Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"stdio.h"
- #include"tubgirl.h"
- FILE *io;
- int n;
- int stack[200001];
- int sp=0;
- long long amps=0;
- int main(){
- int i,j,k,e,d;
- io=fopen("amplifiers.in","r");
- fscanf(io,"%d",&n);
- fscanf(io,"%d",stack);
- for(i=1;i<n;i++){
- fscanf(io,"%d",&e);
- //printf("Bhma %d\n",e);
- if(e>=stack[0]){
- //printf("NEO PEKOP!!!\n");
- amps+=e-stack[sp];
- stack[0]=e;
- sp=0;
- }
- else if(e<stack[sp]){
- //printf("OLO K PIO KATW\n");
- sp++;
- stack[sp]=e;
- }else{
- //printf("ANABAINOMEN\n");
- amps+=e-stack[sp];
- for(;stack[sp]<=e;sp--);
- sp++;
- stack[sp]=e;
- }
- }
- amps+=stack[0]-stack[sp];
- freopen("amplifiers.out","w",io);
- fprintf(io,"%d\n",amps);
- printf("%d\n",amps);
- fclose(io);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement