이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
long long n;
cin >> n;
long long a[n + 1];
vector<pair<long long, long long> >b(n + 2); //wearing and index
for(long long i = 0; i <= n; i++) {
cin >> b[i].first; //to wear
b[i].second = i;
}
for(long long i = 1; i <= n; i++) {
cin >> a[i]; //already wearing
}
sort(a + 1, a + 1 + n);
a[0] = -1;
sort(b.begin(), b.end() - 1);
/*for(long long i = 0; i <= n; i++) {
cout << a[i] << " " << b[i].first << endl;
}*/
long long c[n + 1], ans = 0, d = 0;
long long suf[n + 1];
suf[n] = b[n].first - a[n];
for(long long i = n - 1; i > 0; i--) {
suf[i] = max(suf[i + 1], b[i].first - a[i]);
}
for(long long i = 0; i <= n; i++) {
if(i != 0) {
d = max(d, b[i - 1].first - a[i]);
}
//managers necklace;
if(i != n)
ans = max(d, suf[i + 1]);
else
ans = d;
c[b[i].second] = ans;
}
for(long long i = 0; i <= n; i++) {
cout << c[i] << " ";
}
cout << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |