QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642114#7993. 哈密顿FlandreWA 25ms5012kbC++171.2kb2024-10-15 10:27:052024-10-15 10:27:05

Judging History

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

  • [2024-10-15 10:27:05]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:5012kb
  • [2024-10-15 10:27:05]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = int64_t;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<std::pair<int, int>> p(n);
    for (auto &[x, y] : p) {
        std::cin >> x >> y;
    }

    i64 ans = 0;
    for (auto [x, y] : p) {
        ans += x - y;
    }
    ans = std::max(ans, -ans);

    i64 res = 0;
    int pos = 0;
    std::vector<int> arr;
    for (int i = 0; i < p.size(); ++i) {
        auto [x, y] = p[i];

        res += x + y;
        arr.push_back(-2 * std::min(x, y));
        arr.push_back(-2 * std::max(x, y));

        if ((x + y) < (p[pos].first + p[pos].second)) {
            pos = i;
        }
    }

    arr.erase(std::find(arr.begin(), arr.end(),
                        -2 * std::min(p[pos].first, p[pos].second)));
    arr.erase(std::find(arr.begin(), arr.end(),
                        -2 * std::max(p[pos].first, p[pos].second)));
    res += -2LL * (p[pos].first + p[pos].second);
    std::sort(arr.begin(), arr.end());

    for (int i = arr.size() - 1; i >= arr.size() - n + 2; --i) {
        res += arr[i];
    }

    ans = std::max(ans, res);

    std::cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 10
8 2
4 5

output:

10

result:

ok single line: '10'

Test #2:

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

input:

2
732734236 669531729
368612323 916696032

output:

484881202

result:

ok single line: '484881202'

Test #3:

score: 0
Accepted
time: 21ms
memory: 4960kb

input:

96739
960257511 790393830
766983782 374475134
476482176 529858300
310917487 76906076
81191659 653180897
119832756 362638666
228783015 626981197
74837554 781854003
663345706 153150021
576244413 708232220
842559077 417230462
249522463 815253339
391663517 742521049
60507117 258429449
112143256 81408991...

output:

48459768018811

result:

ok single line: '48459768018811'

Test #4:

score: 0
Accepted
time: 25ms
memory: 5012kb

input:

96785
270111821 467151412
338110212 587493839
880232679 190826309
757074784 388758646
266705411 248083736
932249293 549449409
813345622 128324633
997551674 739367275
118482916 584132988
530659142 718566145
843527299 299368287
351399254 123105310
94363217 996225281
372809651 824469842
227112349 94127...

output:

48406205356958

result:

ok single line: '48406205356958'

Test #5:

score: 0
Accepted
time: 21ms
memory: 4888kb

input:

95819
593599221 692270415
966618937 134812164
440132242 805388141
904873362 529377140
758635067 696205546
760800727 989161190
987540482 498337722
998861034 142965841
153772097 807761700
274559068 988306570
582789805 25357702
672285126 901116830
522823375 37184847
684761653 343776558
745142497 150594...

output:

47840564997532

result:

ok single line: '47840564997532'

Test #6:

score: 0
Accepted
time: 18ms
memory: 4956kb

input:

90554
938804478 938811320
317142499 317149485
342875791 342879712
932975135 932975477
351554666 351570371
550654845 550656473
30714131 30726317
376522835 376526976
69261096 69263592
7393811 7400915
365372935 365376473
859045203 859053499
871017049 871021068
449046577 449046757
427167653 427174136
93...

output:

45267474329725

result:

ok single line: '45267474329725'

Test #7:

score: 0
Accepted
time: 25ms
memory: 4884kb

input:

96261
76198177 76202027
79123680 79124953
513370883 513377553
703603487 703607523
866389252 866390528
139712611 139719009
594522938 594532698
505132016 505134743
605883372 605883641
873915530 873917738
382722258 382729415
540540613 540542021
181157718 181159310
527796215 527806737
137531602 13753437...

output:

48212364519824

result:

ok single line: '48212364519824'

Test #8:

score: 0
Accepted
time: 19ms
memory: 4872kb

input:

91037
326787671 595514434
390694388 871968389
158927546 528620585
409465971 702548500
344910793 636126720
281023782 874898118
11439504 818259011
236508763 545046853
477677678 958867203
302706097 621338311
463199330 835427658
86609075 510670761
420713990 880480770
395156646 579396547
7488975 56384181...

output:

45419010766385

result:

ok single line: '45419010766385'

Test #9:

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

input:

98794
80383727 782796858
137203645 579335675
144425342 811413600
424179404 717502012
910964 875811082
45573824 851384137
464971206 810885972
116742543 999381272
201236005 713855876
257642532 856800308
187899391 774041510
111616203 577225579
442396049 514145473
278843534 670375805
2374052 617021553
3...

output:

49496018572021

result:

ok single line: '49496018572021'

Test #10:

score: -100
Wrong Answer
time: 25ms
memory: 4912kb

input:

99501
498333490 806137098
35925096 850756491
330762085 991137593
485721051 690662947
97287567 718810550
204374526 954732752
280350902 745389794
261096345 804353570
232497375 734787637
192075946 654396123
459149799 534354129
441495626 952937432
11656899 614357926
98839184 565976186
187889698 87856883...

output:

49818206348669

result:

wrong answer 1st lines differ - expected: '49818210067811', found: '49818206348669'