summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-12-18 10:56:22 -0700
committerJack Sangdahl <[email protected]>2024-12-18 10:56:22 -0700
commitc922967b8b2ce6ec78effbc54ae0700c7af1e875 (patch)
tree580cf8da46c5da928307c72a8fc00b999c1795d8
parentb4c9537fd8f13fcfc990f03b3731950fb6ae3759 (diff)
downloadcses-c922967b8b2ce6ec78effbc54ae0700c7af1e875.tar.gz
cses-c922967b8b2ce6ec78effbc54ae0700c7af1e875.zip
1094. increasing array
-rw-r--r--introductory_problems/increasing_array.cpp16
-rw-r--r--introductory_problems/readme.md7
2 files changed, 23 insertions, 0 deletions
diff --git a/introductory_problems/increasing_array.cpp b/introductory_problems/increasing_array.cpp
new file mode 100644
index 0000000..8911474
--- /dev/null
+++ b/introductory_problems/increasing_array.cpp
@@ -0,0 +1,16 @@
+// 1094. Increasing Array
+#include <bits/stdc++.h>
+using namespace std;
+
+int main() {
+ static int arr_size;
+ static long long arr, curr, cnt;
+ scanf("%d", &arr_size);
+ scanf("%lld", &curr);
+ for (int i = 1; i < arr_size; i++) {
+ scanf("%lld", &arr);
+ curr = max(curr, arr);
+ cnt += (curr - arr);
+ }
+ printf("%lld\n", cnt);
+}
diff --git a/introductory_problems/readme.md b/introductory_problems/readme.md
index 78e52cb..cca3339 100644
--- a/introductory_problems/readme.md
+++ b/introductory_problems/readme.md
@@ -20,3 +20,10 @@ You are given a DNA sequence: a string consisting of A, C, G, and T. Your task i
**Input**: The only input line contains a string of `n` characters. (Example: ATTCGGGA)
**Output**: Print one integer: the length of the longest repetition. (Example: 3)
+
+### Increasing Array
+You are given an array of `n` integers. You want to modify the array so that it is increasing, ie. every element is at least as large as the previous element. On each move, you may increase the value of any elementby one. What is the minimum number of moves required?
+
+**Input**: Thefirst input line contains an integer `n`: the size of the array. Then the second line contains `n` integers: the contents of the array. (Example: 5`\n`3 2 5 1 7)
+
+**Output**: Print the minimum number of moves. (Example: 5)