QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188331#5488. Platform Placingtriplem5ds#AC ✓14ms6188kbC++231.6kb2023-09-25 19:03:462023-09-25 19:03:46

Judging History

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

  • [2023-09-25 19:03:46]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:6188kb
  • [2023-09-25 19:03:46]
  • 提交

answer

/// Msaa el 5ra
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i, a, b)  for(int i = a; i < b; i++)
#define all(a)  a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll

using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;

const int N = 5e5 + 5, LG = 18, MOD = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-7;

void doWork() {

    int n, l, r;
    cin >> n >> l >> r;
    vector<ii> ranges;
    vector<int> vec(n);
    f(i, 0, n) {
        cin >> vec[i];
        vec[i] *= 2;
    }
    sort(all(vec));

    f(i, 0, n) {
        int x = vec[i];
        ranges.push_back({x - l, x + l});
        if (i && ranges[i].F < ranges[i - 1].S) {
            cout << "-1\n";
            return;
        }
    }
    int ans = n * l;
    for (int i = 0; i < ranges.size(); i++) {
        int add = r - l;
        if (i)add = min(add, ranges[i].F - ranges[i - 1].S);
        if (i + 1 != ranges.size())add = min(add, ranges[i + 1].F - ranges[i].S);
        ranges[i].F -= add;
        ranges[i].S += add;
        ans += add;
    }
    cout << ans << '\n';

}

int32_t main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE

    int t = 1;
//    cin >> t;
    while (t--) {
        doWork();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1 100
1

output:

100

result:

ok single line: '100'

Test #2:

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

input:

4 1 4
1
6
8
10

output:

11

result:

ok single line: '11'

Test #3:

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

input:

5 1 6
6
7
8
3
5

output:

7

result:

ok single line: '7'

Test #4:

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

input:

2 5 10
1
2

output:

-1

result:

ok single line: '-1'

Test #5:

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

input:

5 1 7
4
6
9
12
14

output:

13

result:

ok single line: '13'

Test #6:

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

input:

6 1 7
4
6
7
10
12
15

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 10ms
memory: 6032kb

input:

100000 27 27
1192240
694414
2285740
2431513
2689363
1355428
498097
1803142
732106
881470
1325728
1343656
9748
2245321
727246
1871047
2413504
1439857
537922
442315
1987174
199477
639766
62587
1345897
53515
1993600
589816
1302643
940114
1949941
1415152
864325
60886
2068579
99118
2681263
2055592
82432
...

output:

2700000

result:

ok single line: '2700000'

Test #8:

score: 0
Accepted
time: 9ms
memory: 6140kb

input:

100000 2 7
1102905
642790
2114975
2250117
2488738
1253837
461380
1667944
677697
815856
1226243
1242797
9119
2077719
673203
1730905
2233264
1332005
498076
409843
1838123
184873
592094
57976
1244889
49637
1844081
545985
1204965
870148
1803677
1309192
800070
56400
1913684
91794
2481302
1901591
76302
54...

output:

700000

result:

ok single line: '700000'

Test #9:

score: 0
Accepted
time: 13ms
memory: 6008kb

input:

100000 2 29
1103183
642683
2116228
2251006
2489444
1254224
460729
1669425
677344
815680
1226750
1243356
8996
2078906
672939
1732245
2234257
1332331
497537
409273
1839894
184141
592138
57887
1245371
49501
1845898
545761
1205459
870015
1805403
1309463
799864
56287
1915302
91537
2481975
1903294
76140
5...

output:

2388768

result:

ok single line: '2388768'

Test #10:

score: 0
Accepted
time: 13ms
memory: 6184kb

input:

100000 2 29
1325225
772465
2537704
2700474
2986537
1506368
553751
2002155
814213
979533
1473689
1493331
10839
2492832
808885
2077696
2680509
1599740
598390
492046
2206935
222198
712071
69789
1495841
59542
2214046
656249
1447904
1044222
2165624
1572517
960626
67919
2296960
110675
2977583
2282799
9196...

output:

2570562

result:

ok single line: '2570562'

Test #11:

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

input:

5 99999 100000
1
100000001
200000001
300000001
400000001

output:

500000

result:

ok single line: '500000'

Test #12:

score: 0
Accepted
time: 13ms
memory: 6188kb

input:

100000 2 100000
1324112
771358
2536865
2698938
2985783
1504779
552992
2002276
813258
979425
1471862
1491711
10750
2492275
807847
2077489
2678959
1599052
597387
490845
2206254
221600
710581
69870
1494100
59767
2213217
655129
1446164
1044161
2165161
1571344
960350
67982
2296383
110348
2976623
2281957
...

output:

2899746

result:

ok single line: '2899746'

Test #13:

score: 0
Accepted
time: 14ms
memory: 6144kb

input:

100000 2 100000
9283106
5406596
17739889
18870564
20875424
10531550
3868578
13999549
5693451
6856226
10292857
10438831
75902
17431987
5655766
14522884
18730397
11188957
4178017
3428187
15429784
1541051
4981635
485774
10454386
413100
15479431
4593776
10117504
7311043
15137208
10999099
6719496
473237
...

output:

17763244

result:

ok single line: '17763244'

Test #14:

score: 0
Accepted
time: 12ms
memory: 3840kb

input:

100000 20 100000
9273198
5385844
17775976
18913022
20902851
10547069
3859081
14033989
5686971
6858335
10313021
10453406
73992
17470972
5649378
14570459
18767527
11203843
4167326
3421862
15461823
1536361
4959708
479964
10470451
414521
15511814
4569143
10133987
7314515
15175051
11008328
6720850
466988...

output:

-1

result:

ok single line: '-1'

Test #15:

score: 0
Accepted
time: 12ms
memory: 6140kb

input:

100000 1 100000
44158
25720
84658
90057
99607
50202
18449
66784
27116
32648
49102
49766
362
83161
26936
69299
89390
53329
19924
16383
73600
7389
23696
2319
49849
1983
73838
21846
48247
34820
72221
52414
32013
2256
76615
3672
99307
76134
3054
21678
38878
15070
3269
95278
47256
92095
22029
75817
97642...

output:

100000

result:

ok single line: '100000'

Test #16:

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

input:

3 1 4
1
2
3

output:

3

result:

ok single line: '3'

Test #17:

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

input:

2 4 9
1
7

output:

12

result:

ok single line: '12'

Test #18:

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

input:

1000 100000 100000
11099958
29099860
70199667
6999976
56099723
46899774
70699666
89699573
16499930
92699565
79599622
32299845
36199827
299999
56799718
79299623
60299706
92999563
64399690
72099660
58999713
82699608
42099793
57899716
36399826
19299915
55199728
85299597
97199542
92399566
35299831
91299...

output:

-1

result:

ok single line: '-1'