cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

increasing_array_1094.cpp (235B)


      1 #include <algorithm>
      2 #include <iostream>
      3 
      4 int main() {
      5 	long long n, prev{0}, sum{0};
      6 	std::cin >> n;
      7 	while (std::cin >> n) {
      8 		sum += std::max<long long>(0, prev - n);
      9 		prev = std::max(prev, n);
     10 	}
     11 	std::cout << sum << std::endl;
     12 }