DuongNhi99

STONES

Dec 10th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. const int N = 1005;
  6.  
  7. int n, m;
  8. int a[N];
  9.  
  10. void solve() {
  11.     a[0] = 0;
  12.     for(int i = 1; i <= n; ++i)
  13.         if(a[i] == -1) {
  14.             a[i] = a[i-1] + m;
  15.         }
  16.  
  17.     for(int i = 1; i <= n; ++i)
  18.         if(a[i] - a[i-1] < m) {
  19.             cout << -1 << ' ';
  20.             return;
  21.         }
  22.  
  23.     for(int i = 1; i <= n; ++i)
  24.         cout << a[i] - a[i-1] << ' ';
  25.  
  26. }
  27.  
  28. int main() {
  29.     //freopen("in.txt", "r", stdin);
  30.     freopen("STONES.inp", "r", stdin);
  31.     freopen("STONES.out", "w", stdout);
  32.     ios_base::sync_with_stdio(false);
  33.     cin.tie(NULL); cout.tie(NULL);
  34.  
  35.     cin >> n >> m;
  36.     for(int i = 1; i <= n; ++i)
  37.         cin >> a[i];
  38.  
  39.     solve();
  40.  
  41.     return 0;
  42. }
  43.  
Add Comment
Please, Sign In to add comment