fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,j;
  6. cin >> t;
  7. for(j=1;j<=t;j++)
  8. {
  9. int N,x,i;
  10. cin >> N >> x;
  11. int a[N];
  12. queue<pair<int,int>> q;
  13. for(i=0;i<N;i++)
  14. {
  15. cin >> a[i];
  16. q.push({a[i],i+1});
  17. }
  18. if (is_sorted(a, a + N))
  19. {
  20. cout <<"Case #" <<j<<": ";
  21. for(i=1;i<=N;i++)
  22. cout<<i<<" ";
  23. cout<<endl;
  24. continue;
  25. }
  26. int r[N];
  27. int l=0;
  28. while(!q.empty())
  29. {
  30. pair<int, int> k = q.front();
  31. if(k.first > x)
  32. {
  33. k.first=k.first-x;
  34. q.pop();
  35. if(q.empty())
  36. {
  37. r[l++]=k.second;
  38. break;
  39. }
  40. q.push(k);
  41. }
  42. else
  43. {
  44. r[l++]=k.second;
  45. q.pop();
  46. }
  47. }
  48. cout <<"Case #" <<j<<": ";
  49. for(i=0;i<N;i++)
  50. {
  51. cout << r[i] <<" ";
  52. }
  53. cout<<endl;
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0s 4328KB
stdin
2
3 3
10 100 1000
5 6
9 10 4 7 2
stdout
Case #1: 1 2 3 
Case #2: 3 5 1 2 4