summaryrefslogtreecommitdiff
path: root/packages/cses/problems/1094.cpp
blob: 56f3886fd1aab7cadbc12046edaffef08bb7ebe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <vector>

using ull = unsigned long long;

int main() {
  ull n;
  auto arr = std::vector<ull>{};

  std::cin >> n;

  std::string type;
  while (std::cin >> type) arr.push_back(std::stoi(type));

  ull count = 0;
  auto last = arr[0];

  for (auto const num : arr) {
    if (num > last) {
      last = num;
      continue;
    }
    count += last - num;
  }

  std::cout << count;
}