QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784904 | #7739. Knapsack | adivse | WA | 54ms | 394824kb | C++20 | 3.4kb | 2024-11-26 16:17:30 | 2024-11-26 16:17:32 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <iomanip>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename T>
void cc(const vector<T>& tem) { for (const auto& x : tem) cout << x << ' '; cout << endl; }
template<typename T>
void cc(const T& a) { cout << a << endl; }
template<typename T1, typename T2>
void cc(const T1& a, const T2& b) { cout << a << ' ' << b << endl; }
template<typename T1, typename T2, typename T3>
void cc(const T1& a, const T2& b, const T3& c) { cout << a << ' ' << b << ' ' << c << endl; }
void cc(const string& s) { cout << s << endl; }
void fileRead() {
#ifdef LOCALL
freopen("D:\\AADVISE\\cppvscode\\CODE\\in.txt", "r", stdin);
freopen("D:\\AADVISE\\cppvscode\\CODE\\out.txt", "w", stdout);
#endif
}
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline double max(double a, double b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
inline double min(double a, double b) { if (a < b) return a; return b; }
void cmax(int& a, const int& b) { if (b > a) a = b; }
void cmin(int& a, const int& b) { if (b < a) a = b; }
void cmin(double& a, const double& b) { if (b < a) a = b; }
void cmax(double& a, const double& b) { if (b > a) a = b; }
using PII = pair<int, int>;
using i128 = __int128;
using vec_int = std::vector<int>;
using vec_char = std::vector<char>;
using vec_double = std::vector<double>;
using vec_int2 = std::vector<std::vector<int>>;
using que_int = std::queue<int>;
//--------------------------------------------------------------------------------
const int N = 5e3 + 10;
const int M = 1e4 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
int suf[N][M];
//--------------------------------------------------------------------------------
//struct or namespace:
struct node {
int ti;
int val;
bool operator<(const node& q1) const {
return q1.val < val;
}
};
node A[N];
priority_queue<int, vector<int>, greater<int>> F;
//--------------------------------------------------------------------------------
signed main() {
fileRead();
kuaidu();
T = 1;
//cin >> T;
while (T--) {
int k;
cin >> n >> m >> k;
rep(i, 1, n) {
// cin >> ti[i] >> val[i];
cin >> A[i].ti >> A[i].val;
}
sort(A + 1, A + n + 1, [&](const node& q1, const node& q2) {
return q1.ti > q2.ti;
});
// rep(i, 1, n) {
// cc(A[i].ti, A[i].val);
// }
rep2(i, n, 1) {
rep(j, 0, m) {
if (A[i].ti <= j) suf[i][j] = max(suf[i + 1][j], suf[i + 1][j - A[i].ti] + A[i].val);
else suf[i][j] = suf[i + 1][j];
}
}
int sum = 0, ans = 0;
int res = 0;
rep(i, 1, n) {
ans += A[i].val;
F.push(A[i].val);
while (F.size() > k) {
auto val = F.top();
ans -= val;
F.pop();
}
cmax(res, ans + suf[i + 1][m]);
}
cc(res);
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3724kb
input:
4 10 1 9 10 10 1 3 5 5 20
output:
35
result:
ok 1 number(s): "35"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 13 2 5 16 5 28 7 44 8 15 8 41
output:
129
result:
ok 1 number(s): "129"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
10 50 1 44 182173741 38 163268500 36 114173760 30 521894533 25 89514235 12 516184197 42 971377551 35 28242326 31 480227821 31 388523197
output:
2009456281
result:
ok 1 number(s): "2009456281"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
10 100 3 23 51015869 9 981426050 76 243762017 64 128189636 4 718411601 48 250140255 17 340478117 68 262055220 40 370503079 4 547232664
output:
3765024872
result:
ok 1 number(s): "3765024872"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
10 500 10 430 981427684 100 458631577 32 453298334 393 716958962 82 120486064 393 561149128 182 518807793 293 950335710 332 159193263 331 280711850
output:
5201000365
result:
ok 1 number(s): "5201000365"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3920kb
input:
10 3000 10 1325 563890842 2007 190665722 1393 874490922 548 279594682 1380 155046921 2666 894516819 770 740325614 2735 643777488 2451 754155860 1068 138544189
output:
5235009059
result:
ok 1 number(s): "5235009059"
Test #7:
score: 0
Accepted
time: 1ms
memory: 4436kb
input:
10 10000 5 108 735534045 6250 87364128 3071 66920092 9343 555321302 9070 759896065 9843 146885261 3083 364637443 7088 370871572 7802 754417134 3125 697204945
output:
4451687859
result:
ok 1 number(s): "4451687859"
Test #8:
score: 0
Accepted
time: 0ms
memory: 9944kb
input:
100 50 61 24 517916473 33 497071404 40 343150837 13 559776223 2 941245278 27 987936903 7 403293890 26 68412861 28 683505315 6 173482637 31 220799032 29 815472376 42 426462445 25 470177395 43 818534622 26 137556071 15 308105056 27 745044655 28 309413241 11 61130780 36 963194467 19 701095156 5 9347020...
output:
44747553879
result:
ok 1 number(s): "44747553879"
Test #9:
score: 0
Accepted
time: 0ms
memory: 9960kb
input:
100 100 42 6 774586597 36 576227741 25 257737545 64 559313526 24 371408966 47 803303316 73 342479452 100 619687258 73 682542576 71 182579788 61 354270154 74 30869398 23 995859349 88 255983493 48 334287458 17 13677067 8 441554725 24 934072639 85 610681655 67 327543259 60 697383634 99 320640445 50 974...
output:
37584168931
result:
ok 1 number(s): "37584168931"
Test #10:
score: 0
Accepted
time: 0ms
memory: 9928kb
input:
100 500 69 117 850222604 135 908209075 281 762241158 193 853115556 202 773483428 88 819344894 37 520809128 225 453191940 252 471232760 298 621091678 378 269475999 19 530190234 459 143203529 477 500583846 446 989780043 50 655756632 321 345085464 423 47668454 132 218063309 325 62856046 474 485855270 1...
output:
42850231504
result:
ok 1 number(s): "42850231504"
Test #11:
score: 0
Accepted
time: 0ms
memory: 10396kb
input:
100 3000 11 2229 113662521 1085 957207016 2571 864419576 2103 102031619 1086 208274995 2005 887504188 2305 803801229 2933 316528833 188 551740507 2720 393827507 2514 955559466 1772 749230500 2676 744768311 2499 772159519 1989 848103925 322 484923680 1757 619590795 571 247505048 1094 438346067 339 99...
output:
17333176908
result:
ok 1 number(s): "17333176908"
Test #12:
score: 0
Accepted
time: 3ms
memory: 11560kb
input:
100 10000 79 7606 40784641 9074 752695754 1153 594817340 9411 584292898 2132 533306184 2666 184228160 2417 356339298 9689 241354004 4927 287380554 7178 158913616 1095 172127175 1688 175994092 4105 75848992 1380 273029283 8421 35148963 432 256969077 5939 82792225 647 500031012 2795 65555568 3395 7706...
output:
44371890318
result:
ok 1 number(s): "44371890318"
Test #13:
score: 0
Accepted
time: 0ms
memory: 40668kb
input:
500 50 126 3 136023068 13 869807356 14 472367566 28 50725598 25 45069923 5 147985467 37 720797915 17 90311040 19 873648042 38 796138954 3 966881081 40 132652908 31 585596518 39 352737389 29 876373760 41 512453383 19 805025356 14 710658601 18 403371907 36 854558198 32 179695697 45 775294020 9 1462316...
output:
124994976191
result:
ok 1 number(s): "124994976191"
Test #14:
score: 0
Accepted
time: 0ms
memory: 40632kb
input:
500 100 98 69 129626760 5 449978106 61 989261186 72 638069575 26 280608378 52 685908155 81 932855739 82 82350114 21 792779442 77 493204907 56 830543473 59 105028460 89 731643951 16 264908763 29 925524933 44 662702166 98 466470962 79 202167196 63 116753433 24 790841938 83 993709118 27 951733632 53 41...
output:
103191714648
result:
ok 1 number(s): "103191714648"
Test #15:
score: 0
Accepted
time: 0ms
memory: 40688kb
input:
500 500 100 380 60038575 204 222150928 205 758606015 5 931871605 405 977650137 493 996917028 41 111185415 303 915854795 412 581469626 95 931716797 480 745749318 16 749573487 217 878988131 193 364284925 27 435793326 481 9814435 314 959936294 375 315763011 305 724135087 290 231187429 197 487213458 357...
output:
107219972338
result:
ok 1 number(s): "107219972338"
Test #16:
score: 0
Accepted
time: 4ms
memory: 41240kb
input:
500 3000 155 885 618166135 1814 400752150 649 826302551 2748 853231980 1650 386604671 30 721008870 2484 887458709 1852 755040724 2313 171979057 1769 893148343 342 397870943 549 848606662 1374 960069408 932 119271788 2006 46601960 2622 893486791 2703 521939745 2133 687850539 1808 931850407 1569 10566...
output:
150198202618
result:
ok 1 number(s): "150198202618"
Test #17:
score: 0
Accepted
time: 3ms
memory: 42748kb
input:
500 10000 39 2164 103861995 3931 307468016 3010 393436072 3416 653030414 6970 794867887 1656 84454065 2169 732024599 6555 453581890 7342 410350010 3201 783977518 4349 922318777 6290 401288294 5183 135437558 8855 659116512 3520 255820440 1262 608543507 496 19150219 2425 358615167 6883 685038845 8879 ...
output:
54344848517
result:
ok 1 number(s): "54344848517"
Test #18:
score: 0
Accepted
time: 0ms
memory: 81572kb
input:
1000 50 796 15 386711393 14 946648902 38 652093661 13 136124305 14 299275346 23 686324157 20 405295225 12 571269091 49 850320620 23 513862466 13 625703085 4 730549435 17 302756512 38 93155670 19 285511180 15 887672509 39 377740062 13 507552700 23 511922533 41 365183175 15 207169111 16 195211892 18 2...
output:
467973714946
result:
ok 1 number(s): "467973714946"
Test #19:
score: 0
Accepted
time: 0ms
memory: 79604kb
input:
1000 100 416 18 324358277 17 197544843 11 247666199 6 821941951 33 274893936 90 501323389 7 405955067 6 587405899 13 39935735 22 292638914 15 836533241 89 878937103 55 551121000 24 815495796 60 539203840 19 916500680 83 626606672 36 777244403 65 816148796 93 601676404 27 114182523 38 509405915 4 545...
output:
350454528075
result:
ok 1 number(s): "350454528075"
Test #20:
score: 0
Accepted
time: 3ms
memory: 81548kb
input:
1000 500 862 429 694961580 8 969717665 267 457202516 235 820776685 408 826711502 27 252523751 72 584284743 27 420910581 192 418560512 449 731150804 440 751739086 438 673225235 382 843689373 109 60096150 257 194696425 352 263612948 295 120072003 435 745616026 312 718497746 51 336989191 444 902654159 ...
output:
492713511906
result:
ok 1 number(s): "492713511906"
Test #21:
score: 0
Accepted
time: 4ms
memory: 80296kb
input:
1000 3000 351 727 8847709 2613 622538643 1461 97349529 1467 131003214 1043 126909307 532 219814384 2830 650278892 534 187011265 1312 789736632 1773 150503473 2766 702593294 1351 942888530 1656 764929540 2760 688345433 2131 310426897 1623 689276961 2098 193762961 2863 772562087 489 210523205 1687 791...
output:
317718205329
result:
ok 1 number(s): "317718205329"
Test #22:
score: 0
Accepted
time: 9ms
memory: 81884kb
input:
1000 10000 778 8901 374587545 7728 686705536 8090 632699030 8973 846089348 3693 855315786 8280 466401395 3762 691477129 7041 299407306 1348 72339995 266 48085564 6096 845178428 3340 512295215 9113 834760223 7761 585397824 4738 188388966 6971 458993083 3511 658239404 7788 959071523 5940 499882747 958...
output:
473643556169
result:
ok 1 number(s): "473643556169"
Test #23:
score: 0
Accepted
time: 0ms
memory: 237184kb
input:
3000 50 270 45 491619379 46 456136181 6 150276090 15 307922938 22 476230253 31 627626576 18 552999720 4 450084166 26 273018445 24 169175025 16 656547585 5 340241062 46 390744556 48 670230402 6 786162621 28 709925602 32 537681828 46 789083627 10 264958422 20 154381571 24 560364557 30 790662742 17 502...
output:
290860604546
result:
ok 1 number(s): "290860604546"
Test #24:
score: 0
Accepted
time: 7ms
memory: 237336kb
input:
3000 100 1090 95 929126436 78 344445858 98 596187078 81 402574836 60 159026070 98 213043026 1 447783807 58 731790292 68 365118050 47 337266628 37 702913172 29 76108832 3 526350941 1 914180379 68 211064953 69 603459740 8 77781147 69 849933501 74 430480358 60 232768589 11 51843442 56 346787151 100 879...
output:
924830589780
result:
ok 1 number(s): "924830589780"
Test #25:
score: 0
Accepted
time: 0ms
memory: 235368kb
input:
3000 500 459 405 4762442 77 116618680 254 805723396 206 846119970 138 415876340 143 374308795 65 921080779 391 420070782 255 153808234 366 775778518 354 323151721 474 575429668 231 378727825 178 13556540 265 426366050 206 395282408 121 276279182 268 113272420 220 892637820 218 968081376 24 545347782...
output:
460875644145
result:
ok 1 number(s): "460875644145"
Test #26:
score: 0
Accepted
time: 11ms
memory: 236328kb
input:
3000 3000 1123 2006 392902738 1337 679829030 286 921787343 270 240243524 1758 110206510 2323 449831592 1610 263249990 2063 940608857 1872 351221360 2785 890423328 2200 930205448 2396 350502927 2195 439948015 1794 954001143 1225 568246284 1390 922613232 1729 734554054 752 126982613 2181 167748492 242...
output:
926856325003
result:
ok 1 number(s): "926856325003"
Test #27:
score: 0
Accepted
time: 28ms
memory: 238276kb
input:
3000 10000 2445 9916 60955521 1311 546281196 8271 450785814 3811 340452615 6033 10211620 7021 920120703 5451 129814122 5163 99511373 5958 811056057 2900 348514492 529 300995446 5984 886829548 6799 628556572 8875 909284688 6902 228353975 4150 707453233 2608 433754217 5158 506050856 8125 823984360 320...
output:
1452952580705
result:
ok 1 number(s): "1452952580705"
Test #28:
score: 0
Accepted
time: 3ms
memory: 392948kb
input:
5000 50 190 32 301560068 25 260590756 20 793682711 25 774688866 21 798409351 36 568928995 16 140895703 49 33931946 8 550492078 29 119454880 7 247200596 2 949932689 29 38541113 4 807113645 50 581781359 41 386954504 25 697623595 18 775647258 42 17994312 48 533514559 37 208527299 44 681080887 16 176062...
output:
218126002582
result:
ok 1 number(s): "218126002582"
Test #29:
score: 0
Accepted
time: 0ms
memory: 393016kb
input:
5000 100 3823 75 238927298 46 491346873 89 944707958 51 132950824 94 748190908 11 629795367 94 489612547 21 25917789 34 250108876 75 86927046 55 129101614 66 978313264 48 206613585 69 457575361 76 737701875 6 735129199 21 383731430 2 217589894 87 309653136 24 863860774 90 549312873 77 333911491 4 62...
output:
2320118624303
result:
ok 1 number(s): "2320118624303"
Test #30:
score: 0
Accepted
time: 3ms
memory: 393072kb
input:
5000 500 2394 177 609530601 441 263519695 141 714052787 380 426752854 472 5041178 156 86028432 59 667942223 446 859422471 9 38799061 498 230471640 472 44307459 11 772601396 80 353957765 247 407208418 70 393194460 152 377208763 342 727453657 293 480928813 229 212002086 90 744397754 12 42817213 419 44...
output:
1852150745930
result:
ok 1 number(s): "1852150745930"
Test #31:
score: 0
Accepted
time: 12ms
memory: 393492kb
input:
5000 3000 3487 285 71925064 766 32086712 214 746225157 176 494708026 178 388471010 1819 825072993 390 876221089 2888 249496048 2431 912706087 796 775567375 2827 157817601 1145 463150028 2734 264709594 2235 219656853 2126 385874182 2349 745884095 656 425088251 1641 631146243 169 124973778 171 8716049...
output:
2301328281584
result:
ok 1 number(s): "2301328281584"
Test #32:
score: 0
Accepted
time: 43ms
memory: 394728kb
input:
5000 10000 2172 8227 747323497 702 815922265 8451 123648405 4457 539848585 4182 870140159 8465 78872716 5652 273183820 182 634774225 6376 694996312 8639 794167613 4962 312102064 8628 526205097 1781 717320216 5797 792980065 6361 268318983 5921 250880678 3194 769077542 2128 53030189 311 443053269 6826...
output:
1744764005003
result:
ok 1 number(s): "1744764005003"
Test #33:
score: 0
Accepted
time: 0ms
memory: 40704kb
input:
500 100 6 69 129626760 5 449978106 61 989261186 72 638069575 26 280608378 52 685908155 81 932855739 82 82350114 21 792779442 77 493204907 56 830543473 59 105028460 89 731643951 16 264908763 29 925524933 44 662702166 98 466470962 79 202167196 63 116753433 24 790841938 83 993709118 27 951733632 53 415...
output:
20882560809
result:
ok 1 number(s): "20882560809"
Test #34:
score: 0
Accepted
time: 0ms
memory: 41084kb
input:
500 2000 0 717 749378724 1821 456186461 914 854370780 630 531878947 686 546997860 225 813872363 1274 323198011 508 992548471 1127 940365060 505 811316843 614 469644931 556 683679438 1169 918875427 910 990336141 992 634221171 1549 40563192 1349 393030052 1801 143794499 1953 806679053 1977 280975110 6...
output:
16556234961
result:
ok 1 number(s): "16556234961"
Test #35:
score: 0
Accepted
time: 0ms
memory: 42744kb
input:
500 10000 6 2164 103861995 3931 307468016 3010 393436072 3416 653030414 6970 794867887 1656 84454065 2169 732024599 6555 453581890 7342 410350010 3201 783977518 4349 922318777 6290 401288294 5183 135437558 8855 659116512 3520 255820440 1262 608543507 496 19150219 2425 358615167 6883 685038845 8879 7...
output:
23324356892
result:
ok 1 number(s): "23324356892"
Test #36:
score: 0
Accepted
time: 0ms
memory: 79596kb
input:
1000 100 9 18 324358277 17 197544843 11 247666199 6 821941951 33 274893936 90 501323389 7 405955067 6 587405899 13 39935735 22 292638914 15 836533241 89 878937103 55 551121000 24 815495796 60 539203840 19 916500680 83 626606672 36 777244403 65 816148796 93 601676404 27 114182523 38 509405915 4 54512...
output:
31453001024
result:
ok 1 number(s): "31453001024"
Test #37:
score: 0
Accepted
time: 4ms
memory: 81656kb
input:
1000 2000 0 1559 285284491 620 972940250 918 830450462 53 954874373 1887 992335200 1535 722743285 1325 526209682 383 719486309 1934 558122635 509 628480486 38 629143091 1845 222671706 746 18702856 1034 264442490 310 898046108 255 836353362 552 64853268 428 83281856 930 235094955 1391 261381112 507 8...
output:
30955836975
result:
ok 1 number(s): "30955836975"
Test #38:
score: 0
Accepted
time: 3ms
memory: 81852kb
input:
1000 10000 8 8901 374587545 7728 686705536 8090 632699030 8973 846089348 3693 855315786 8280 466401395 3762 691477129 7041 299407306 1348 72339995 266 48085564 6096 845178428 3340 512295215 9113 834760223 7761 585397824 4738 188388966 6971 458993083 3511 658239404 7788 959071523 5940 499882747 9580 ...
output:
34688476173
result:
ok 1 number(s): "34688476173"
Test #39:
score: 0
Accepted
time: 4ms
memory: 237236kb
input:
3000 100 4 95 929126436 78 344445858 98 596187078 81 402574836 60 159026070 98 213043026 1 447783807 58 731790292 68 365118050 47 337266628 37 702913172 29 76108832 3 526350941 1 914180379 68 211064953 69 603459740 8 77781147 69 849933501 74 430480358 60 232768589 11 51843442 56 346787151 100 879520...
output:
42863706412
result:
ok 1 number(s): "42863706412"
Test #40:
score: 0
Accepted
time: 12ms
memory: 235872kb
input:
3000 2000 8 838 819082624 345 30230637 1550 949855572 959 64114683 306 270599699 222 247727789 401 844213485 719 883149308 1982 824640067 1520 513624533 1665 1979436 1890 480542999 1477 253529843 1771 825065496 1211 155865494 21 364656929 182 605644361 317 437702381 622 897352945 133 154146094 1357 ...
output:
54423020406
result:
ok 1 number(s): "54423020406"
Test #41:
score: 0
Accepted
time: 19ms
memory: 238348kb
input:
3000 10000 8 9916 60955521 1311 546281196 8271 450785814 3811 340452615 6033 10211620 7021 920120703 5451 129814122 5163 99511373 5958 811056057 2900 348514492 529 300995446 5984 886829548 6799 628556572 8875 909284688 6902 228353975 4150 707453233 2608 433754217 5158 506050856 8125 823984360 3203 7...
output:
51014870332
result:
ok 1 number(s): "51014870332"
Test #42:
score: 0
Accepted
time: 3ms
memory: 393028kb
input:
5000 100 4 75 238927298 46 491346873 89 944707958 51 132950824 94 748190908 11 629795367 94 489612547 21 25917789 34 250108876 75 86927046 55 129101614 66 978313264 48 206613585 69 457575361 76 737701875 6 735129199 21 383731430 2 217589894 87 309653136 24 863860774 90 549312873 77 333911491 4 62397...
output:
45754238305
result:
ok 1 number(s): "45754238305"
Test #43:
score: 0
Accepted
time: 12ms
memory: 393388kb
input:
5000 2000 5 1924 203137653 773 382488320 1479 334101898 569 613546481 21 403640007 718 622969190 181 311960391 1248 781971091 541 826316282 532 103801284 1100 524558885 639 888157396 17 783324126 509 90721206 1409 973493393 1276 333151984 1301 1211262 206 792122907 313 854578232 1579 46911077 1503 5...
output:
64438494935
result:
ok 1 number(s): "64438494935"
Test #44:
score: 0
Accepted
time: 54ms
memory: 394824kb
input:
5000 10000 8 8227 747323497 702 815922265 8451 123648405 4457 539848585 4182 870140159 8465 78872716 5652 273183820 182 634774225 6376 694996312 8639 794167613 4962 312102064 8628 526205097 1781 717320216 5797 792980065 6361 268318983 5921 250880678 3194 769077542 2128 53030189 311 443053269 6826 59...
output:
73081922809
result:
ok 1 number(s): "73081922809"
Test #45:
score: -100
Wrong Answer
time: 0ms
memory: 3680kb
input:
1 1 0 1 1
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'