思路:
首先找大于等于n的,最小的,没有的话就找最小的
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
int n;
int a[maxn];
multiset<int> b;
int ans[maxn];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for(int i = 1; i <= n; ++i) {
int x; scanf("%d", &x);
b.insert(x);
}
set<int>::iterator t;
set<int>::iterator t1;
for(int i = 1; i <= n; ++i) {
int x = (n-a[i]);
t = b.lower_bound(x);
if(t != b.end()) {
ans[i] = (a[i] + *t) % n;
b.erase(t);
}
else {
t1 = b.begin();
ans[i] = (a[i] + *t1) % n;
b.erase(t1);
}
}
for(int i = 1; i <= n; ++i) {
if(i > 1) printf(" ");
printf("%d", ans[i]);
}
return 0;
}