#include <bits/stdc++.h>
//#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 1e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
signed main()
{
ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--)
{
int n;
cin >> n;
vector<pii>a(n+1);
vector<int>b(n);
for(int i=0; i<=n; i++)
{
cin >> a[i].fi;
a[i].sc = i;
}
for(int i=0; i<n; i++)cin >> b[i];
sort(all(b));
sort(all(a));
vector<int> razlika(n);
for(int i=0; i<n; i++)razlika[i] = a[i+1].fi - b[i];
vector<int> prefmax(n+1,0);
vector<int> sufmax(n+1,0);
for(int i=n-1; i>=0; i--)sufmax[i] = max(sufmax[i+1], razlika[i]);
vector<int> rez(n+1);
rez[a[0].sc] = sufmax[0];
for(int i=1; i<=n; i++)
{
prefmax[i] = max(prefmax[i-1], a[i-1].fi - b[i-1]);
rez[a[i].sc] = max(prefmax[i], sufmax[i]);
}
//for(auto x:prefmax)cout << x << " ";cout <<endl;
//for(auto x:sufmax)cout << x << " ";cout <<endl;
for(auto x:rez)cout << x << " ";cout <<endl;
}
}
Compilation message
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:51:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
51 | for(auto x:rez)cout << x << " ";cout <<endl;
| ^~~
ho_t1.cpp:51:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
51 | for(auto x:rez)cout << x << " ";cout <<endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
472 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
376 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
472 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
472 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
376 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
472 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
53 ms |
10836 KB |
Output is correct |
34 |
Correct |
61 ms |
11240 KB |
Output is correct |
35 |
Correct |
54 ms |
11088 KB |
Output is correct |
36 |
Correct |
58 ms |
11324 KB |
Output is correct |
37 |
Correct |
55 ms |
11628 KB |
Output is correct |
38 |
Correct |
56 ms |
11600 KB |
Output is correct |
39 |
Correct |
52 ms |
10580 KB |
Output is correct |
40 |
Correct |
53 ms |
10576 KB |
Output is correct |
41 |
Correct |
53 ms |
10632 KB |
Output is correct |
42 |
Correct |
53 ms |
10580 KB |
Output is correct |
43 |
Correct |
52 ms |
10584 KB |
Output is correct |
44 |
Correct |
51 ms |
10068 KB |
Output is correct |
45 |
Correct |
53 ms |
10376 KB |
Output is correct |
46 |
Correct |
52 ms |
10064 KB |
Output is correct |
47 |
Correct |
49 ms |
10324 KB |
Output is correct |
48 |
Correct |
50 ms |
10344 KB |
Output is correct |
49 |
Correct |
55 ms |
10760 KB |
Output is correct |
50 |
Correct |
55 ms |
11068 KB |
Output is correct |
51 |
Correct |
61 ms |
10980 KB |
Output is correct |
52 |
Correct |
62 ms |
10860 KB |
Output is correct |
53 |
Correct |
55 ms |
10836 KB |
Output is correct |