Josif_tepe

Untitled

May 3rd, 2026
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. const ll INF = 1e18;
  7. int main(){
  8.     ios_base::sync_with_stdio(false);
  9.     int n, k;
  10.     cin >> n >> k;
  11.    
  12.     vector<int> v(n);
  13.     for(int i = 0; i < n; i++) {
  14.         cin >> v[i];
  15.     }
  16.    
  17.     ll till_now = 0;
  18.     ll res = INF;
  19.     for(int i = 0; i < n; i++) {
  20.         ll x = 0;
  21.         vector<int> v2 = v;
  22.         bool ok = true;
  23.         if(i + k - 1 < n) {
  24.             for(int j = i + 1; j < i + k and j < n; j++) {
  25.                 if(v2[j] > v2[j - 1]) {
  26.                     ok = false;
  27.                     break;
  28.                 }
  29.                 if(v2[j - 1] - v2[j] != 1) {
  30.                     x += abs(v2[j] - v2[j - 1] + 1) * 5;
  31.                     v2[j] = v2[j - 1] - 1;
  32.                     if(v2[j] < 1) {
  33.                         ok = false;
  34.                         break;
  35.                     }
  36.                 }
  37.             }
  38.            
  39.             if(ok) {
  40.                 res = min(res, x + till_now);
  41.             }
  42.         }
  43.        
  44.         till_now += 10;
  45.     }
  46.    
  47.     if(res == INF) {
  48.         res = -1;
  49.     }
  50.     cout << res << endl;
  51.  
  52.     return 0;
  53. }
  54.  
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment