Created
August 9, 2024 07:11
-
-
Save rishabhgargg/b52fff1a0c013884bc9c8d996c3d0a69 to your computer and use it in GitHub Desktop.
1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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