Submission #226461

# Submission time Handle Problem Language Result Execution time Memory
226461 2020-04-23T21:02:11 Z thebes Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
315 ms 18680 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int MN = 2e5+5;
int N, i, b[MN], ans[MN];
pii a[MN];
multiset<int> dif;

int main(){
    for(scanf("%d",&N),i=1;i<=N+1;i++){
        scanf("%d",&a[i].first);
        a[i].second=i;
    }
    for(i=1;i<=N;i++)
        scanf("%d",&b[i]);
    sort(b+1,b+N+1);
    sort(a+1,a+N+2,[](pii i,pii j){return i.first<j.first;});
    for(i=1;i<=N;i++)
        dif.insert(a[i].first-b[i]);
    for(i=N+1;i>=1;i--){
        auto it=dif.end(); it--;
        ans[a[i].second]=max(0,*it);
        if(i!=1){
            int ot = i-1;
            dif.erase(dif.find(a[i-1].first-b[ot]));
            dif.insert(a[i].first-b[ot]);
        }
    }
    for(i=1;i<=N+1;i++)
        printf("%d ",ans[i]);
    printf("\n");
    return 0;
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:13:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d",&N),i=1;i<=N+1;i++){
         ~~~~~~~~~~~~~~^~~~
ho_t1.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i].first);
         ~~~~~^~~~~~~~~~~~~~~~~~
ho_t1.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&b[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 7 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 7 ms 512 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 7 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 7 ms 512 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
33 Correct 249 ms 17400 KB Output is correct
34 Correct 269 ms 18296 KB Output is correct
35 Correct 243 ms 17528 KB Output is correct
36 Correct 265 ms 18168 KB Output is correct
37 Correct 251 ms 18680 KB Output is correct
38 Correct 245 ms 18484 KB Output is correct
39 Correct 276 ms 17400 KB Output is correct
40 Correct 279 ms 17288 KB Output is correct
41 Correct 315 ms 17584 KB Output is correct
42 Correct 275 ms 17528 KB Output is correct
43 Correct 279 ms 17400 KB Output is correct
44 Correct 269 ms 16888 KB Output is correct
45 Correct 271 ms 17016 KB Output is correct
46 Correct 265 ms 16888 KB Output is correct
47 Correct 187 ms 17272 KB Output is correct
48 Correct 190 ms 17400 KB Output is correct
49 Correct 291 ms 17912 KB Output is correct
50 Correct 285 ms 17912 KB Output is correct
51 Correct 287 ms 17912 KB Output is correct
52 Correct 309 ms 18040 KB Output is correct
53 Correct 291 ms 17912 KB Output is correct