QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376677#3167. ICPC Campckiseki#AC ✓1958ms35052kbC++201.6kb2024-04-04 15:00:502024-04-04 15:00:50

Judging History

你现在查看的是最新测评结果

  • [2024-04-04 15:00:50]
  • 评测
  • 测评结果:AC
  • 用时:1958ms
  • 内存:35052kb
  • [2024-04-04 15:00:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << "\n";
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, p, q, s;
  cin >> n >> p >> q >> s;
  multiset<int> a, b_;
  for (int i = 0; i < p; ++i) {
    int x;
    cin >> x;
    a.insert(x);
  }
  for (int i = 0; i < q; ++i) {
    int x;
    cin >> x;
    b_.insert(x);
  }
  
  auto valid = [&](int d) {
    auto b = b_;
    vector<pair<int, int>> v;
    for (auto ai : a) {
      v.emplace_back(min(ai + d, s - ai), ai - d);
    }
    ranges::sort(v);
    int c = n;
    for (auto [r, l] : v) {
      auto it = b.lower_bound(l);
      if (it == b.end())
        continue;
      if (*it > r)
        continue;
      b.erase(it);
      if (--c == 0)
        break;
    }
    return c == 0;
  };

  int L = -1, R = 1'000'000'000;
  if (not valid(R)) {
    cout << "-1\n";
    return 0;
  }

  while (R - L > 1) {
    int M = (L + R) >> 1;
    if (valid(M))
      R = M;
    else
      L = M;
  }
  cout << R << '\n';
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3536kb

input:

3 4 5 10
3
4
4
9
0
1
5
6
6

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

4 4 4 15
1
5
10
12
1
3
10
14

output:

13

result:

ok single line: '13'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

4 4 4 10
1
12
5
10
1
10
3
14

output:

-1

result:

ok single line: '-1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

4 4 4 30
1
5
10
12
1
3
10
14

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

4 5 5 10
1
3
3
4
9
0
2
5
7
8

output:

4

result:

ok single line: '4'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

3 3 3 4
1
1
3
3
1
0

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

3 3 3 1000000000
0
0
1000000000
0
1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

1 1 1 0
1
1

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3488kb

input:

3 5 5 1000000000
1
100
200
300
400
2
89
211
290
410

output:

10

result:

ok single line: '10'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

5 5 5 100
1
10
20
90
100
0
10
80
90
99

output:

100

result:

ok single line: '100'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

6 6 6 25
1
7
8
13
14
15
1
10
11
12
12
13

output:

5

result:

ok single line: '5'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

3 9 9 30
0
1
12
22
28
29
30
50
51
0
1
12
22
28
29
30
50
51

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

1 1 4 10
5
1
3
6
9

output:

2

result:

ok single line: '2'

Test #14:

score: 0
Accepted
time: 1ms
memory: 3832kb

input:

1 4 1 10
1
3
6
9
5

output:

2

result:

ok single line: '2'

Test #15:

score: 0
Accepted
time: 1383ms
memory: 35036kb

input:

200000 200000 200000 1000000000
107180
2049941
2059655
2054840
124091
103395
175331
184717
190908
113910
2041452
2078004
2009005
114559
2039747
112331
132171
2050441
2095717
2044077
137515
168621
2098897
2094290
169133
2005806
167333
2000616
2001240
193639
129155
2005697
2071739
192411
138391
122679...

output:

999799998

result:

ok single line: '999799998'

Test #16:

score: 0
Accepted
time: 1347ms
memory: 35044kb

input:

200000 200000 200000 1000000000
28505
999927038
999959123
999946674
999985091
999998850
64601
999938822
83467
999926212
999929514
999965309
23830
999902208
62506
28929
999980852
999978842
21242
33622
999953101
999962534
79705
999958415
94821
41799
999944987
999945039
999982939
999983899
24750
999943...

output:

1000000000

result:

ok single line: '1000000000'

Test #17:

score: 0
Accepted
time: 845ms
memory: 34896kb

input:

100000 200000 200000 5
8
9
3
0
6
9
1
2
10
7
2
0
7
5
3
9
8
1
2
2
2
4
4
5
6
0
0
4
2
1
4
2
7
5
4
3
3
1
7
9
0
1
1
7
10
10
8
8
10
8
7
10
9
0
10
8
9
5
10
4
0
10
8
3
3
2
5
2
2
1
5
1
5
0
3
4
0
10
2
3
10
2
8
8
10
4
2
1
8
5
6
6
10
10
4
1
3
10
4
9
5
0
7
10
0
9
10
10
6
7
4
1
8
8
3
4
6
2
2
2
1
3
2
3
7
9
1
9
1
4
...

output:

5

result:

ok single line: '5'

Test #18:

score: 0
Accepted
time: 950ms
memory: 35020kb

input:

199999 199999 200000 15
9
9
6
8
7
0
6
4
3
6
2
10
1
3
9
8
2
1
10
6
6
4
5
6
4
4
10
5
9
1
6
3
3
1
7
3
6
1
1
7
7
8
4
10
4
8
2
1
10
1
4
10
10
7
4
0
5
0
9
8
10
0
2
8
7
3
0
0
6
0
2
2
7
7
9
8
2
7
7
1
3
9
10
2
3
4
10
6
8
5
7
7
1
6
0
8
6
7
8
7
8
0
8
3
4
0
7
6
1
3
0
4
0
6
3
6
8
8
0
0
2
0
7
3
1
1
5
4
8
7
0
10
2...

output:

6

result:

ok single line: '6'

Test #19:

score: 0
Accepted
time: 888ms
memory: 35048kb

input:

123456 199999 199998 8
6
2
6
9
3
6
4
6
2
1
6
4
2
2
10
0
0
9
0
6
6
4
0
6
1
8
2
7
10
4
7
10
6
9
9
7
8
9
5
2
6
1
5
6
8
5
0
7
7
6
10
6
4
7
0
4
2
10
2
0
3
0
0
5
9
9
8
10
8
10
6
4
4
8
8
1
6
5
9
3
2
10
0
2
1
2
9
4
7
10
5
7
10
0
4
0
2
9
3
6
5
6
3
4
9
2
9
3
1
4
7
0
7
8
6
0
2
0
2
1
5
0
10
2
5
7
4
9
3
1
10
0
5...

output:

4

result:

ok single line: '4'

Test #20:

score: 0
Accepted
time: 1711ms
memory: 34952kb

input:

50000 200000 200000 500000000
610081114
333776675
620871342
101159319
956662600
848856113
914422044
871150418
857693653
237952826
452171083
941020562
788779660
933849843
370996573
665703051
382775772
541623769
668187622
989573075
80576714
119482138
397167501
465954658
974080197
677300808
465978160
5...

output:

440033

result:

ok single line: '440033'

Test #21:

score: 0
Accepted
time: 1647ms
memory: 35052kb

input:

100000 200000 200000 1000000
299580
16063
159195
343047
944042
482948
579566
287027
451618
546265
5965
160723
633809
964578
931774
855004
275997
59319
134340
530241
252626
323189
692301
673911
212050
425338
80598
942779
807773
950882
829398
32143
600931
360293
362874
212340
423306
217524
110065
6374...

output:

3495

result:

ok single line: '3495'

Test #22:

score: 0
Accepted
time: 165ms
memory: 33360kb

input:

100000 200000 200000 500000000
960443662
873041408
404555069
106990526
603252293
472278989
830670299
125195407
437835463
435199393
80837055
708379167
662398669
93287908
85628142
282832335
149954169
48126613
941899338
909389244
772513662
581135366
305138946
923788526
640981653
214003423
860316866
987...

output:

-1

result:

ok single line: '-1'

Test #23:

score: 0
Accepted
time: 155ms
memory: 33284kb

input:

200000 200000 200000 1000000
470243
528561
6696
344466
119807
2446
688761
617955
272023
226518
847369
330136
831122
239795
78952
752961
240468
144078
428534
472930
301725
265335
6925
323452
644964
330293
39334
357985
34030
984809
660696
247780
780217
794610
717763
743584
139296
628181
522485
218638
...

output:

-1

result:

ok single line: '-1'

Test #24:

score: 0
Accepted
time: 1511ms
memory: 34868kb

input:

200000 200000 200000 999999997
656177006
663928089
288734542
812194455
528246170
396095199
638303668
28252340
370376338
840329146
637669185
840500136
550724800
375925403
537724438
573678960
365626221
506403797
494769518
346192348
398316477
45405373
968000839
597508258
658825271
728422488
483162327
6...

output:

999999301

result:

ok single line: '999999301'

Test #25:

score: 0
Accepted
time: 1562ms
memory: 34920kb

input:

200000 200000 200000 199999
108970
78774
113660
143317
58595
12575
64612
92095
199319
18543
174387
76672
144468
106113
56707
12424
31457
145604
186964
5915
170295
162143
191710
23614
57071
47939
41458
147518
195771
91412
20167
139954
22662
120665
105610
134015
114246
84581
172981
106691
26403
184192...

output:

199999

result:

ok single line: '199999'

Test #26:

score: 0
Accepted
time: 1478ms
memory: 34932kb

input:

200000 200000 200000 399998
41761
140955
63803
93009
146973
41259
162339
57248
191820
136655
149566
87633
196705
114044
122246
193843
159416
18630
156839
179119
49855
195715
131061
161932
197232
33824
109414
152286
35727
117651
115546
76057
50946
39112
139132
158357
157915
161314
185146
35578
185769...

output:

281

result:

ok single line: '281'

Test #27:

score: 0
Accepted
time: 1683ms
memory: 34812kb

input:

100000 200000 200000 2001493
717001
1964820
715027
502596
1985668
895754
1699895
1331591
93897
548120
1545704
1854023
158243
1074029
522643
1200949
983471
1652619
1680706
547590
1857870
1494590
574339
926985
1771994
562367
300752
169311
873211
1159740
1142537
218023
408385
24116
696752
1071968
63439...

output:

1083

result:

ok single line: '1083'

Test #28:

score: 0
Accepted
time: 1866ms
memory: 35040kb

input:

100000 200000 200000 200020155
6909443
61300203
34049524
94352407
86370208
36147229
93408915
46598105
165328377
116416482
17384349
1366231
58937409
171379303
70004596
61319228
78386651
23695282
188108171
146630069
87087059
88379483
20682128
169350047
43600478
6532310
132656207
10339658
54048141
3525...

output:

13600

result:

ok single line: '13600'

Test #29:

score: 0
Accepted
time: 1958ms
memory: 35024kb

input:

100000 200000 200000 999991471
994832549
2994795
824111195
608244455
32119530
867237100
78068620
876433090
107447894
227326957
282730686
804370382
456064468
646123413
667837039
351693944
565777492
448839676
20343890
649093416
829721156
468435291
246446112
984632737
534467633
349518735
340633294
3570...

output:

8803

result:

ok single line: '8803'

Test #30:

score: 0
Accepted
time: 1619ms
memory: 34820kb

input:

200000 200000 200000 399999
48348
26565
112390
57813
135900
144029
133963
177
154980
116351
158144
102897
161796
193782
116214
28107
20381
184357
41722
30366
123013
126479
179846
132067
83288
175120
148962
126906
83864
48624
138453
79573
88424
198591
22118
153577
71187
39411
91416
164907
199661
1634...

output:

1

result:

ok single line: '1'

Test #31:

score: 0
Accepted
time: 1507ms
memory: 35052kb

input:

100000 200000 200000 300000
145572
74218
191889
92608
18794
68887
90323
31040
132983
106213
86815
68402
63889
133765
175950
39876
10087
102965
53315
95409
163355
131849
76995
74221
49260
162362
123650
57313
30812
13399
76572
33753
42581
102172
129325
47883
166543
117149
156984
123790
128773
39410
14...

output:

0

result:

ok single line: '0'

Test #32:

score: 0
Accepted
time: 696ms
memory: 34908kb

input:

199999 200000 200000 14
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
...

output:

0

result:

ok single line: '0'

Test #33:

score: 0
Accepted
time: 1485ms
memory: 34872kb

input:

1 200000 200000 5000000
313476209
41591220
348337424
655901727
3907213
863143495
384127805
503566331
247487203
122220730
520109785
755497744
890786361
538196014
470430548
587287424
319963662
665721721
930667327
234562055
920791943
344072045
821076819
626150954
428166094
532743833
391878205
524741820...

output:

88

result:

ok single line: '88'

Test #34:

score: 0
Accepted
time: 1451ms
memory: 34928kb

input:

43460 200000 200000 296788440
719592435
218149251
479235474
886185135
789131199
255526481
776561142
92893574
897244003
579441410
37744986
277129382
861854781
912109711
804298511
803535963
116296511
592316188
181727921
886235445
711912309
995786373
35135360
619378187
280918782
674246036
2476750
65471...

output:

136604297

result:

ok single line: '136604297'

Test #35:

score: 0
Accepted
time: 1799ms
memory: 34916kb

input:

59616 200000 200000 776637696
298627970
496714324
793506533
880268530
201384705
895000084
319849987
548836158
470024015
339278629
337298927
392732149
959241611
181959341
384143346
242837928
517041411
286155256
663955778
648013402
541535866
103769502
182110508
715705058
490196024
620707156
879646876
...

output:

8258

result:

ok single line: '8258'

Test #36:

score: 0
Accepted
time: 154ms
memory: 33380kb

input:

75902 200000 200000 301527906
853288027
843540954
480625953
392476858
21612687
200214667
409551573
547749860
898283833
909627348
120904372
481933786
992850041
689967306
335865238
826739949
557542489
615997468
523646008
177997668
919221757
313108628
803389546
987776044
728618132
186466840
152007651
3...

output:

-1

result:

ok single line: '-1'