Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef long long ll;
- const ll INF = 1e18;
- int main(){
- ios_base::sync_with_stdio(false);
- int n, k;
- cin >> n >> k;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- ll till_now = 0;
- ll res = INF;
- for(int i = 0; i < n; i++) {
- ll x = 0;
- vector<int> v2 = v;
- bool ok = true;
- if(i + k - 1 < n) {
- for(int j = i + 1; j < i + k and j < n; j++) {
- if(v2[j] > v2[j - 1]) {
- ok = false;
- break;
- }
- if(v2[j - 1] - v2[j] != 1) {
- x += abs(v2[j] - v2[j - 1] + 1) * 5;
- v2[j] = v2[j - 1] - 1;
- if(v2[j] < 1) {
- ok = false;
- break;
- }
- }
- }
- if(ok) {
- res = min(res, x + till_now);
- }
- }
- till_now += 10;
- }
- if(res == INF) {
- res = -1;
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment