Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. long long int numberOfBuilding, floodHeight;
  8. numberOfBuilding = floodHeight = -1;
  9. scanf("%lld %lld", &numberOfBuilding, &floodHeight);
  10.  
  11. long long int highestVolumeOfWater = 0, currentVolume = 0, isFilling = 0;
  12.  
  13. for (int i = 0; i < numberOfBuilding; i++)
  14. {
  15. long long int currentBuildingHeight = -1;
  16. scanf("%lld", &currentBuildingHeight);
  17.  
  18. if (currentBuildingHeight >= floodHeight)
  19. isFilling = 0;
  20. else if (currentBuildingHeight < floodHeight
  21. && isFilling == 0)
  22. isFilling = 1;
  23.  
  24. if (isFilling)
  25. {
  26. currentVolume += floodHeight - currentBuildingHeight;
  27. // printf("(building, volume) : %d %d\n", i + 1, currentVolume);
  28. }
  29.  
  30. if (!isFilling || i == numberOfBuilding - 1)
  31. {
  32. if (currentVolume > highestVolumeOfWater)
  33. {
  34. highestVolumeOfWater = currentVolume;
  35. currentVolume = 0;
  36. }
  37. }
  38. }
  39.  
  40. // printf("Biggest Volume : %d\n", highestVolumeOfWater);
  41. printf("%lld\n", highestVolumeOfWater);
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement