Advertisement
juanjo12x

UVA_11683_Laser_Sculpture

Jul 14th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <cctype>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <string>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main(int argc, char** argv) {
  11.     int h,l,laser,max;
  12.     int arr[100001];
  13.     while(scanf("%d %d",&h,&l)){
  14.        laser=0;max=h;
  15.         if(h==0 && l==0) break;
  16.        
  17.         for(int i=0;i<l;i++){
  18.             scanf("%d",&arr[i]);
  19.         }
  20.        
  21.         for(int j=l-1;j>=0;j--){
  22.             if(max>arr[j]){
  23.                 laser+=max-arr[j];
  24.                
  25.             }
  26.             max=arr[j];
  27.         }
  28.                
  29.         printf("%d\n",laser);
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement