Advertisement
Naxocist

Illumination Optimization

Apr 29th, 2023
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using pi = pair<int, int>;
  5.  
  6. void solve() {
  7.     int m, y, n; cin >> m >> y >> n;
  8.  
  9.     int end = 0, ok = 1, cnt = 0, c = 0;
  10.     for(int i=0; i<n; ++i) {
  11.         int x; cin >> x;
  12.         int l = max(0, x-y), r = min(m, x+y);
  13.         if(l > c) ok = 0;
  14.         if(l > end) {
  15.             cnt ++ ;
  16.             end = c;
  17.         }
  18.         c = r;
  19.     }
  20.     if(end != m) cnt++;
  21.     if(!ok || c != m) cout << "IMPOSSIBLE\n";
  22.     else cout << cnt << '\n';
  23. }
  24.  
  25. int main() {
  26.     int q; cin >> q;
  27.     for(int i=1; i<=q; ++i) {
  28.         cout << "Case #" << i << ": ";
  29.         solve();
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement