Advertisement
mohammedehab2002

Untitled

Jul 14th, 2020
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[100005],cnt[100005];
  6.  
  7. int main()
  8.  
  9. {
  10.  
  11.     int n,m,cur=0;
  12.  
  13.     scanf("%d%d",&n,&m);
  14.  
  15.     int p=m+1;
  16.  
  17.     cnt[0]=1;
  18.  
  19.     for (int i=1;i<n;i++)
  20.  
  21.     {
  22.  
  23.         scanf("%d",&a[i]);
  24.  
  25.         cur=(cur+a[i])%(m+1);
  26.  
  27.         cnt[cur]++;
  28.  
  29.     }
  30.  
  31.     for (int i=m;i>=0;i--)
  32.  
  33.     {
  34.  
  35.         cnt[i]+=cnt[i+1];
  36.  
  37.         if (cnt[i]>=p-i)
  38.  
  39.         {
  40.  
  41.             p=i;
  42.  
  43.             cnt[i]=0;
  44.  
  45.         }
  46.  
  47.     }
  48.  
  49.     p=m+1-p;
  50.  
  51.     for (int i=0;i<n;i++)
  52.  
  53.     {
  54.  
  55.         p=(p+a[i])%(m+1);
  56.  
  57.         printf("%d%c",p+1," \n"[i==n-1]);
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement