QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389342 | #4368. Oil | TWTP_TCTF# | AC ✓ | 996ms | 4020kb | C++20 | 1.8kb | 2024-04-14 09:52:39 | 2024-04-14 09:52:40 |
Judging History
answer
#include<iostream>
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define rep(i, a, b) for(int i = a ; i < b ; i ++)
#define sz(v) (int)v.size()
#define all(v) begin(v), end(v)
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e3 + 5;
int y[N], x1[N], x2[N];
int n;
ll solve(int x, int h) {
vector<pair<pair<ld, ld>, int> > res;
for (int i = 0; i < n; i++) {
if (y[i] == h)continue;
ld dy = y[i] - h;
ld dx1 = x1[i] - x, dx2 = x2[i] - x;
// dx1 / dy
ld l = -h * dx1 / dy;
ld r = -h * dx2 / dy;
if (l > r)swap(l, r);
res.push_back({{l, r}, abs(x1[i] - x2[i])});
}
sort(res.begin(), res.end());
ll ans = 0, sum = 0;
priority_queue<pair<ld, int> > q;
for (auto i: res) {
sum += i.second;
while (!q.empty() && -q.top().first < i.first.first) {
sum -= q.top().second;
q.pop();
}
q.push({-i.first.second, i.second});
ans = max(ans, sum);
}
return ans;
}
void doWork() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x1[i] >> x2[i] >> y[i];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans = max(ans, abs(x1[i] - x2[i]) + solve(x1[i], y[i]));
ans = max(ans, abs(x1[i] - x2[i]) + solve(x2[i], y[i]));
}
cout << ans;
// dx / dy = s
// y => y * s + c
// y * s + c = X
// ys + c >=l && ys + c <=r
// s>= (l-c) / y && s<= (r-c)/y
// (l-c) / y <= s <= (r-c) / y
}
int main() {
IO
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
doWork();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
5 100 180 20 30 60 30 70 110 40 10 40 50 0 80 70
output:
200
result:
ok single line: '200'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 50 60 10 -42 -42 20 25 0 10
output:
25
result:
ok single line: '25'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 -100 180 20
output:
280
result:
ok single line: '280'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
1 -1000000 1000000 1
output:
2000000
result:
ok single line: '2000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 -1000000 1000000 1000000
output:
2000000
result:
ok single line: '2000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
1 -1000000 -999999 1000000
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
1 1000000 999999 1000000
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 -1000 0 200 1 1000 200
output:
1000
result:
ok single line: '1000'
Test #9:
score: 0
Accepted
time: 434ms
memory: 3800kb
input:
1000 737368 429284 959063 -548693 513523 43074 243164 -465669 860567 422975 -244747 588631 -136535 -470055 501433 -580596 -269833 22422 476738 -448258 866889 358773 563858 950905 -923261 208187 66835 -295330 444422 360513 -903435 841952 491761 377801 520064 65247 479135 -307498 426574 -794533 -46924...
output:
490622362
result:
ok single line: '490622362'
Test #10:
score: 0
Accepted
time: 433ms
memory: 4000kb
input:
1000 393505 133958 96751 942939 72421 396439 -822694 -718897 366172 -833366 91559 389785 28456 -507666 398767 -178646 616985 288351 465302 236829 106233 -911686 531549 436738 946908 -619546 27459 840101 -51671 27117 904596 -552691 993402 -379495 -968868 996117 -993434 826061 624577 390359 750548 209...
output:
474626777
result:
ok single line: '474626777'
Test #11:
score: 0
Accepted
time: 434ms
memory: 3704kb
input:
1000 91153 -919136 629430 -928593 -340764 946503 -958781 151370 414466 776584 -865178 350581 266056 -678142 180528 855892 -61597 800115 -150759 821898 16625 286683 401612 387028 -104779 -495288 75284 -292434 725113 64163 925796 -886633 920311 -995416 275385 423913 -922152 395549 705834 138194 618689...
output:
482990936
result:
ok single line: '482990936'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
3 10 20 10 20 30 20 10 20 30
output:
30
result:
ok single line: '30'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
3 10 20 30 20 30 20 10 20 10
output:
30
result:
ok single line: '30'
Test #14:
score: 0
Accepted
time: 90ms
memory: 3704kb
input:
1000 -500 -499 3 -499 -498 4 -498 -497 3 -497 -496 4 -496 -495 3 -495 -494 4 -494 -493 3 -493 -492 4 -492 -491 3 -491 -490 4 -490 -489 3 -489 -488 4 -488 -487 3 -487 -486 4 -486 -485 3 -485 -484 4 -484 -483 3 -483 -482 4 -482 -481 3 -481 -480 4 -480 -479 3 -479 -478 4 -478 -477 3 -477 -476 4 -476 -4...
output:
4
result:
ok single line: '4'
Test #15:
score: 0
Accepted
time: 91ms
memory: 3708kb
input:
1000 -500 -499 3 -499 -498 4 -498 -497 3 -497 -496 4 -496 -495 3 -495 -494 4 -494 -493 3 -493 -492 4 -492 -491 3 -491 -490 4 -490 -489 3 -489 -488 4 -488 -487 3 -487 -486 4 -486 -485 3 -485 -484 4 -484 -483 3 -483 -482 4 -482 -481 3 -481 -480 4 -480 -479 3 -479 -478 4 -478 -477 3 -477 -476 4 -476 -4...
output:
4
result:
ok single line: '4'
Test #16:
score: 0
Accepted
time: 79ms
memory: 3712kb
input:
500 885456 935548 893024 644787 -652783 650298 808938 947594 815852 432081 -622268 435774 142740 -169702 143960 856557 925094 863878 261261 -736938 263494 930033 956540 937982 417456 924584 421024 594945 978958 600030 893646 933174 901284 547677 775565 552358 883935 916485 891490 821457 984796 82847...
output:
244491195
result:
ok single line: '244491195'
Test #17:
score: 0
Accepted
time: 50ms
memory: 3708kb
input:
500 45689 45688 429334 -25319 -25320 894329 522056 522055 312322 -235913 -235914 80549 -426659 -426658 805356 411907 411906 645880 426220 426221 921612 -231572 -231571 910658 -875534 -875533 98045 846207 846206 829899 537791 537790 316936 307422 307423 401580 944769 944770 344664 979191 979192 10757...
output:
3
result:
ok single line: '3'
Test #18:
score: 0
Accepted
time: 46ms
memory: 3900kb
input:
500 179265 179266 321892 -979392 -979391 937361 253303 253304 662093 15752 15753 454134 852294 852295 799415 -412075 -412074 216608 727687 727686 146860 -594461 -594460 201360 866097 866096 403699 558297 558298 877893 759626 759627 517730 -409242 -409243 646944 -117540 -117541 298990 -291402 -291401...
output:
3
result:
ok single line: '3'
Test #19:
score: 0
Accepted
time: 50ms
memory: 3704kb
input:
500 93517 93518 342725 -526642 -526641 673580 -677576 -677575 72016 945873 945874 659771 353454 353453 240805 -829016 -829015 865082 164010 164009 830895 560978 560979 311174 -692476 -692477 84711 536284 536283 727900 335375 335374 145312 417370 417369 61814 826406 826407 429567 -958557 -958556 9207...
output:
3
result:
ok single line: '3'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3556kb
input:
1000 -314183 -313894 798067 -425756 -425118 798067 -292017 -290420 798067 -886889 -885538 798067 -467401 -466095 798067 -854994 -854815 798067 -513964 -513655 798067 -738214 -737165 798067 -370302 -370033 798067 -520695 -520311 798067 939776 940229 798067 -507203 -505083 798067 -430399 -430073 79806...
output:
10859
result:
ok single line: '10859'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
1000 382451 382452 78441 857836 857837 78441 901408 901409 78441 553681 553682 78441 958497 958498 78441 558159 558160 78441 -25805 -25804 78441 -347668 -347667 78441 -273817 -273816 78441 831018 831019 78441 -388683 -388682 78441 133277 133278 78441 687349 687350 78441 -840786 -840785 78441 -928903...
output:
1
result:
ok single line: '1'
Test #22:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
40 -1000000 -999999 1 1000000 999999 1 -1000000 -999999 2 1000000 999999 2 -999997 -999996 3 999997 999996 3 -999991 -999990 4 999991 999990 4 -999979 -999978 5 999979 999978 5 -999955 -999954 6 999955 999954 6 -999907 -999906 7 999907 999906 7 -999811 -999810 8 999811 999810 8 -999619 -999618 9 999...
output:
2
result:
ok single line: '2'
Test #23:
score: 0
Accepted
time: 433ms
memory: 4000kb
input:
1000 -562471 -912107 906506 -274879 -684768 698460 -874397 -188848 93604 -28794 -705403 609340 -167399 672073 966800 574383 -905547 886644 -606533 550812 888727 1562 230412 549342 677277 -834070 132706 -449549 540411 221803 73145 952104 336019 829568 -100383 692127 829833 -903703 193961 -174794 -191...
output:
475321294
result:
ok single line: '475321294'
Test #24:
score: 0
Accepted
time: 436ms
memory: 4020kb
input:
1000 535429 -631156 23269 512514 443281 542836 819566 -570924 519963 590031 -433565 264096 923294 160073 940091 -593408 -22399 532315 684799 -775238 49209 147113 -229349 981796 -756171 -526454 792463 206727 -23932 752629 -966010 983032 506651 890735 874240 566955 116980 217648 481666 -256065 621601 ...
output:
520621781
result:
ok single line: '520621781'
Test #25:
score: 0
Accepted
time: 434ms
memory: 3756kb
input:
1000 -539833 289597 151993 -97690 368210 28207 -324216 -553930 596542 -186165 -607098 656556 -66638 955440 205040 395039 329828 131162 226670 -134576 92227 -955914 -406966 866136 92055 -780943 194200 911334 415803 292298 556810 -852515 101714 -343033 992805 225276 -63525 846157 772818 335979 638756 ...
output:
491071907
result:
ok single line: '491071907'
Test #26:
score: 0
Accepted
time: 278ms
memory: 3708kb
input:
1000 -575337 -573660 851311 686087 691270 873892 -638060 -639269 772876 -720300 -722235 245651 716357 725256 738087 488406 490701 246614 -727750 -731177 325662 -991421 -999235 200753 537028 533528 669169 122969 125027 367320 -760777 -756503 49216 246388 237769 474145 -531151 -521821 289201 489068 48...
output:
105038
result:
ok single line: '105038'
Test #27:
score: 0
Accepted
time: 278ms
memory: 3696kb
input:
1000 205431 197003 881149 -864713 -867761 485945 103404 107198 990073 74999 77596 650806 -255915 -253437 874190 744948 749615 48710 815593 825399 598966 191407 193371 814024 701448 692913 225997 -291367 -294844 760471 -28317 -23376 104332 190642 187676 514001 805351 797488 445584 -402481 -408400 532...
output:
109988
result:
ok single line: '109988'
Test #28:
score: 0
Accepted
time: 277ms
memory: 3704kb
input:
1000 -558787 -551785 414529 120708 117367 973219 52208 51253 365345 -817392 -819311 546764 364514 372039 29492 -455925 -458922 588004 723878 733467 500184 977966 972616 688853 -34109 -37970 906557 918076 913630 206217 432948 425377 848473 88518 85204 705668 -254455 -250148 690900 842171 838210 58930...
output:
95852
result:
ok single line: '95852'
Test #29:
score: 0
Accepted
time: 226ms
memory: 3760kb
input:
1000 -157084 -157031 185405 -452796 -452881 463752 591511 591484 977598 523880 523929 61733 476997 477001 518007 -172268 -172276 65342 727194 727244 48770 966693 966690 801748 -223375 -223328 848052 -510495 -510411 126903 461655 461593 227992 411293 411309 931068 -58673 -58621 284529 -90156 -90124 7...
output:
366
result:
ok single line: '366'
Test #30:
score: 0
Accepted
time: 223ms
memory: 3996kb
input:
1000 306232 306284 502945 433479 433417 876592 -210218 -210157 872427 -252484 -252474 757623 -407893 -407815 227373 932894 932800 44474 -871695 -871765 212158 187159 187201 638974 894022 894071 760736 411140 411171 305793 -336595 -336512 231004 383131 383196 518029 -528070 -528079 894547 120550 1206...
output:
322
result:
ok single line: '322'
Test #31:
score: 0
Accepted
time: 228ms
memory: 3760kb
input:
1000 -238925 -238996 224432 -752092 -752047 183057 286146 286090 253260 585403 585354 117949 -20067 -20048 257759 -323288 -323286 945046 -966696 -966599 767354 218085 218065 687818 -134562 -134477 320406 799157 799235 316087 492773 492780 625156 85051 85116 33060 1045 1061 788035 30271 30327 852769 ...
output:
371
result:
ok single line: '371'
Test #32:
score: 0
Accepted
time: 216ms
memory: 3736kb
input:
1000 765193 765193 377744 -784373 -784373 391530 -330706 -330706 475509 349530 349530 887257 -583109 -583109 158120 699638 699638 268352 771899 771899 78706 753056 753056 546394 117356 117356 137367 931180 931180 957933 225981 225981 669848 -62771 -62771 32869 206592 206592 706224 637628 637628 5675...
output:
0
result:
ok single line: '0'
Test #33:
score: 0
Accepted
time: 996ms
memory: 3736kb
input:
2000 -562311 -562310 985766 594472 594473 372479 -178003 -178002 762574 -253391 -253390 553791 -138948 -138947 90598 -97412 -97411 874559 659874 659875 292807 424559 424560 312347 105222 105223 716911 -902757 -902756 11807 411176 411177 673969 342551 342552 650414 -956681 -956680 76972 -194819 -1948...
output:
4
result:
ok single line: '4'
Test #34:
score: 0
Accepted
time: 965ms
memory: 3740kb
input:
2000 -887753 -887752 404724 724046 724047 957791 -703081 -703080 340344 927562 927563 103216 992630 992631 352035 -587464 -587463 966759 -189871 -189870 717462 -155303 -155302 479334 209953 209954 344773 -881275 -881274 476467 -455010 -455009 154987 -61478 -61477 957555 -211119 -211118 15455 858290 ...
output:
8
result:
ok single line: '8'
Test #35:
score: 0
Accepted
time: 957ms
memory: 3740kb
input:
2000 -13398 -13397 651308 438778 438779 106392 -980056 -980055 476576 -971701 -971700 861497 338379 338380 271416 -467547 -467546 287153 -644885 -644884 136944 -81843 -81842 753597 -530265 -530264 429395 -596683 -596682 9812 -287498 -287497 447937 -350707 -350706 253609 -822875 -822874 21630 -947072...
output:
16
result:
ok single line: '16'
Test #36:
score: 0
Accepted
time: 961ms
memory: 3796kb
input:
2000 675859 675860 556169 -584853 -584852 667147 226791 226792 232710 -638320 -638319 444718 -725115 -725114 631591 65948 65949 610220 -2171 -2170 60676 -217210 -217209 497472 274559 274560 637695 -768466 -768465 144682 -717968 -717967 41946 -575055 -575054 426546 944403 944404 21382 346596 346597 9...
output:
28
result:
ok single line: '28'
Test #37:
score: 0
Accepted
time: 248ms
memory: 3744kb
input:
1000 -1000000 1000000 227965 -1000000 1000000 959376 -1000000 1000000 625867 1000000 -1000000 68512 1000000 -1000000 267242 -1000000 1000000 628405 -1000000 1000000 185557 -1000000 1000000 831681 -1000000 1000000 830877 -1000000 1000000 883925 -1000000 1000000 881126 -1000000 1000000 351724 -1000000...
output:
2000000000
result:
ok single line: '2000000000'
Test #38:
score: 0
Accepted
time: 343ms
memory: 3744kb
input:
1000 0 198476 519794 -500000 45298 128787 242746 500000 632799 140298 -1000000 371287 266496 1000000 693424 282570 -1000000 734455 -1000000 146834 387971 -500000 311488 808272 185898 1000000 487687 -500000 263760 686440 286294 -1000000 743961 351464 -1000000 910316 19268 -500000 62342 65666 0 180779...
output:
649382066
result:
ok single line: '649382066'