Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <string.h>
- int main()
- {
- long long int numberOfBuilding, floodHeight;
- numberOfBuilding = floodHeight = -1;
- scanf("%lld %lld", &numberOfBuilding, &floodHeight);
- long long int highestVolumeOfWater = 0, currentVolume = 0, isFilling = 0;
- for (int i = 0; i < numberOfBuilding; i++)
- {
- long long int currentBuildingHeight = -1;
- scanf("%lld", ¤tBuildingHeight);
- if (currentBuildingHeight >= floodHeight)
- isFilling = 0;
- else if (currentBuildingHeight < floodHeight
- && isFilling == 0)
- isFilling = 1;
- if (isFilling)
- {
- currentVolume += floodHeight - currentBuildingHeight;
- // printf("(building, volume) : %d %d\n", i + 1, currentVolume);
- }
- if (!isFilling || i == numberOfBuilding - 1)
- {
- if (currentVolume > highestVolumeOfWater)
- {
- highestVolumeOfWater = currentVolume;
- currentVolume = 0;
- }
- }
- }
- // printf("Biggest Volume : %d\n", highestVolumeOfWater);
- printf("%lld\n", highestVolumeOfWater);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement