fork download
  1. #include <bits/stdc++.h>
  2. using ll = long long;
  3. using ld = long double;
  4. using namespace std;
  5.  
  6. int main() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9.  
  10. ll n;
  11. cin >> n;
  12. vector<ll> a(n), b(n);
  13. set<ll> s;
  14. vector<ll> cnts(n);
  15. for (ll i = 0; i < n; i++) {
  16. cin >> a[i];
  17. }
  18. for (ll i = 0; i < n; i++) {
  19. cin >> b[i];
  20. cnts[b[i]]++;
  21. if (cnts[b[i]] == 1) {
  22. s.insert(b[i]);
  23. }
  24. }
  25.  
  26. for (ll i = 0; i < n; i++) {
  27. auto it = s.lower_bound(n - a[i]);
  28. ll num = *it;
  29. if (it == s.end() && *it < n - a[i]) {
  30. num = *s.lower_bound(a[i]);
  31. }
  32. cout << (a[i] + num) % n << ' ';
  33. cnts[num]--;
  34. if (cnts[num] == 0) {
  35. s.erase(num);
  36. }
  37. }
  38. cout << endl;
  39. }
Success #stdin #stdout 0s 15240KB
stdin
4
0 1 2 1
3 2 1 1
stdout
1 0 0 2