Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rishabhgargg/b52fff1a0c013884bc9c8d996c3d0a69 to your computer and use it in GitHub Desktop.
Save rishabhgargg/b52fff1a0c013884bc9c8d996c3d0a69 to your computer and use it in GitHub Desktop.
1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int min_coupons(vector<int>& arr) {
int n = arr.size();
vector<int> dp(n, 1);
for (int i = 1; i < n; ++i) {
if (arr[i] >= arr[i - 1]) {
dp[i] = dp[i - 1];
} else {
dp[i] = dp[i - 1] + arr[i - 1] - arr[i] + 1;
arr[i] = arr[i - 1] + 1;
}
}
return dp[n - 1] - 1;
}
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
cout << min_coupons(arr) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment