Advertisement
tepyotin2

Chores

Dec 9th, 2023
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     ios_base::sync_with_stdio(0), cin.tie(0);
  7.     // freopen("chores.in", "r", stdin);
  8.     int n, l;
  9.     cin >> n >> l;
  10.     int adds[l];
  11.     int cow[n];
  12.     for(int i=1; i<=l; i++){
  13.         cin >> adds[i];
  14.         // cout << "adds[i]: " << adds[i] << '\n';
  15.     }
  16.     for(int i=1; i<=n; i++){
  17.         cow[i] = i;
  18.     }
  19.     // cout << "HI" << '\n';
  20.     int idx = 0;
  21.     int active = 0;
  22.     int val = 0;
  23.     for(int i=1; i<=n-1; i++){
  24.         idx++;
  25.         active = adds[idx];
  26.         // cout << "adds[idx]: " << adds[idx] << '\n';
  27.         int skip = 0;
  28.         // cout << "loop: " << i << "(" << val << " + " << active+skip << ")";
  29.         for(int j=1; j<=active; j++){
  30.             val++;
  31.             if(val>n){
  32.                 val=val%n;
  33.             }
  34.             while(cow[val] == 0){
  35.                 val++;
  36.                 if(val>n){
  37.                     val=val%n;
  38.                 }
  39.                 skip++;
  40.                 // cout << "HI" << '\n';
  41.             }
  42.         }
  43.         // cout << ", check array - > " << ", skip: " << skip << ", used: " << val << '\n';
  44.         cow[val] = 0;
  45.         idx = idx%l;
  46.     }
  47.     // cout << "HI2" << '\n';
  48.     for(int i=1; i<=n-1; i++){
  49.         if(cow[i] != 0){
  50.             cout << cow[i] << '\n';
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement