#include #include #include #include /** * 1626. Best Team With No Conflicts * * You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team. * However, the basketball team is not allowed to have conflicts. A conflict exists if a younger player has a strictly higher score than an older player. A conflict does not occur between players of the same age. * Given two lists, scores and ages, where each scores[i] and ages[i] represents the score and age of the ith player, respectively, return the highest overall score of all possible basketball teams. */ class Solution { public: static int bestTeamScore(const std::vector& scores, const std::vector& ages) { const int n = scores.size(); std::vector> s(n); for (int i = 0; i < n; ++i) s[i] = {scores[i], ages[i]}; std::sort(s.begin(), s.end()); int dp[1005]{}, ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) if (s[j].second <= s[i].second) dp[i] = std::max(dp[j], dp[i]); ans = std::max(dp[i] += s[i].first, ans); } return ans; } }; int f() { return Solution::bestTeamScore( {744402,475462,174940,23658,49714,313242,934279,795006,33970,767299,908169,334948,936800,339523,297605,155205,528393,512636,213766,163240,219600,878400,917573,885197,472677,539323,211739,819570,375826,526350,98334,882377,557530,536249,473757,195827,293700,231546,898067,131786,403026,531643,555444,395691,485863,394774,685678,467294,961937,955772,974904,348089,195375,769422,660164,274699,721076,357270,572691,131119,4070,355986,602954,653688,795969,470867,34954,191379,17311,530827,641519,854853,795982,446964,663805,193294,982637,798788,462439,553185,240109,182424,873206,971225,592726,573227,885232,233085,350763,841454,477405,603201,18633,294014,951177,136472,655178,989709,620279,881012,871855,865742,85904,940048,853437,511427,811685,591303,269073,967384,646978,785041,403056,716572,782510,220021,523146,914753,642970,673617,512897,871833,725677,984724,37186,478049,152403,952394,378388,948134,231907,616653,282985,925196,528878,846056,866378,365364,662627,369390,45395,183133,245080,256128,554164,701018,670096,491490,688316,882722,243866,414859,206883,993117,79360,807033,778235,144054,246759,996545,516008,74723,550742,620664,935432,577462,176356,730992,662699,878990,642760,348573,988759,665036,383517,789492,931073,482780,309196,132078,582034,424129,723414,828087,329803,326373,371307,591391,526769,829244,580748,745976,958529,957228,8621,243334,34197,312272,389545,492258,327137,306760,573850,231461,452346,113384,195933,209368,136974,569084,146554,256534,432547,123412,555461,522635,422043,511877,740682,328951,841567,155458,417077,889910,577137,202317,717478,620911,999446,159853,292220,99270,524004,330325,442111,919136,877135,235990,32314,572557,267365,890136,17940,220132,844902,390103,461997,751702,693347,10335,511171,696602,373,752967,868422,371129,949155,14680,623458,876945,683376,36369,983298,299576,546089,76866,428518,767035,75992,579514,412885,865201,789276,796331,135080,556271,791466,110052,436682,986415,762450,123352,720578,597521,45520,885494,779771,102975,593423,701784,593257,664251,841769,369041,576505,547246,690103,689624,902968,617481,779695,592800,250451,534834,53110,944564,244881,245235,770056,53986,62708,636605,470501,616996,738827,509008,166786,613758,19307,199437,311934,513659,497518,638465,208062,215398,869048,230661,839005,593557,9362,67090,748831,141166,494300,194368,503984,740735,30070,570532,301108,760450,237953,245370,800753,544879,798849,365363,936462,426603,409085,96877,372320,611502,609693,770266,827472,839750,199606,76319,85145,372372,122539,742365,270649,447368,142112,192403,950306,295644,14979,77162,611425,103372,851808,243391,147200,869968,602212,203786,350624,654122,344685,608148,462527,221511,456332,485887,350315,981329,360946,413602,283698,938447,203671,284583,519292,69680,506506,325599,693981,211854,886151,995914,727888,632032,920168,509808,716421,937577,28204,163401,463809,660981,186166,379553,341387,487022,354382,554043,3209,206886,145424,854969,961512,926908,536826,844558,63874,827062,433771,596969,694482,495818,264636,657697,252517,109375,829794,499568,389818,759124,803905,931893,507785,733468,75013,44869,395592,104171,317544,452978,133882,283086,791387,262361,483078,265763,877849,979373,221982,738668,707281,316137,771146,84232,956014,469053,164247,924720,11105,799007,164971,341764,691079,436033,453497,536415,991130,491473,396679,196669,530320,246813,564519,531598,641875,108630,311304,441745,150012,605292,72751,529473,497696,750283,51522,325374,386418,125159,980700,10446,774720,98762,597820,79983,551588,359235,584389,413282,554058,221516,909612,977594,940151,137202,444190,258835,180308,831774,73625,231171,768473,792816,461747,5393,447720,184808,466856,638598,976566,544203,375335,538830,487955,326388,719519,606549,25429,894397,764133,147153,425889,943159,375726,457680,73291,669224,376354,63308,832896,576251,319038,252719,848329,25015,990255,186145,805284,439348,392937,661174,286469,334792,547725,389888,178036,488252,740017,886347,917978,527015,604910,504944,447302,389226,980521,137368,424188,349779,454086,126471,989749,823043,956154,602414,297324,634320,505921,988367,281641,895357,64211,76419,888428,169022,560039,921483,602675,729970,822976,621148,154291,875074,508692,977852,81911,196324,425397,543981,194082,822311,41885,176718,947387,435130,375553,225460,882237,155176,355944,364861,329229,280012,527036,374841,703376,842266,615961,405748,604597,359709,858138,223534,298599,108143,827602,834579,302039,185929,549496,216908,129695,826935,63137,874864,52653,392128,515824,279481,975056,913827,737580,343038,675043,665677,158063,740259,466241,167732,981424,59428,803796,484969,130145,787619,637667,584561,55072,906118,277600,725039,524743,530844,872485,307898,934116,111945,158318,368682,841115,878916,401135,233254,522264,987164,540806,803855,98388,121118,581051,74254,833576,983519,404042,367049,55541,626205,151189,719446,809201,511477,156637,224742,642173,924074,160078,44884,305943,993349,187544,134286,602710,429626,816846,744089,895377,558140,160359,125839,255399,613517,570392,77870,870846,558459,26754,818877,967178,527044,947800,660317,855702,693972,81692,962774,712790,613384,94883,172581,792263,721617,307831,623887,89364,208294,965942,539534,825273,964138,897847,643729,489564,345645,979966,171447,867914,422434,183610,384336,707963,205206,642205,720058,638714,789026,671998,670743,997283,719948,57559,300263,609214,173549,225735,450606,916354,262663,193292,129092,41199,517244,513532,791469,158513,233373,987769,63862,798264,702736,828639,167807,580649,388956,43509,873444,321574,556587,92148,496186,523623,985004,664953,815635,21529,489627,286002,751857,360817,803866,298429,831174,653196,449978,314225,563937,73619,606898,166559,885881,220589,192184,330036,230884,954133,632987,61881,219387,614279,58160,720741,38721,674688,694994,237654,740638,9917,903630,928821,466571,550653,610222,579555,5874,9062,26644}, {69,188,760,415,700,858,58,709,959,504,849,495,484,704,251,50,593,336,990,194,679,101,593,724,133,123,268,672,119,1000,793,553,88,604,63,378,848,833,449,989,648,853,600,833,577,742,706,417,619,992,33,623,243,819,754,893,29,176,785,928,791,344,951,214,103,3,205,423,510,764,22,419,738,357,919,22,388,192,841,301,953,601,158,630,456,196,268,886,662,373,257,17,110,678,276,363,38,248,868,89,518,341,644,828,835,981,109,17,589,362,462,696,910,199,894,949,968,96,53,925,730,810,553,9,965,301,161,826,290,992,906,800,667,620,970,887,780,292,182,682,244,166,992,47,315,520,798,811,363,3,369,622,419,905,17,606,252,866,283,438,441,8,305,452,658,222,545,296,539,224,754,644,286,204,973,389,201,252,561,379,137,166,149,292,657,354,840,538,963,842,144,48,757,958,942,994,628,95,369,71,252,821,761,924,685,79,262,508,252,404,645,958,576,874,399,646,163,814,37,298,483,368,916,427,388,713,703,423,706,858,614,496,803,17,220,770,510,862,598,265,327,567,408,875,416,780,43,765,645,11,498,485,686,838,100,884,756,577,201,879,527,47,395,240,845,575,265,320,684,234,54,267,471,616,630,374,33,683,963,46,261,918,293,439,580,203,681,706,400,391,741,335,936,413,527,316,909,543,662,588,221,806,275,437,505,224,844,860,937,892,552,186,651,793,270,632,793,332,583,576,975,62,925,713,316,445,27,66,678,849,344,527,657,844,778,927,54,953,215,159,463,615,6,697,814,122,353,174,27,700,737,190,64,933,790,771,201,237,977,248,385,466,561,135,248,773,950,421,549,779,988,889,844,116,789,629,836,400,316,200,662,449,373,945,795,749,264,614,666,761,705,244,615,61,292,490,833,695,320,615,948,320,50,142,934,661,678,682,659,875,420,554,636,485,358,644,785,483,48,248,391,352,480,291,523,59,355,225,673,940,691,91,749,700,556,234,266,358,369,179,550,396,504,562,30,83,491,732,448,812,640,665,764,621,264,344,153,52,105,137,950,849,681,810,992,636,578,451,349,349,296,576,946,53,16,163,155,488,473,374,852,462,445,417,713,502,42,103,677,927,996,32,615,695,911,660,5,405,715,658,20,314,369,897,951,936,43,285,790,267,754,660,655,456,933,453,187,634,679,321,796,915,377,783,806,788,494,589,71,129,643,931,786,573,251,616,478,167,742,287,932,458,124,555,60,504,719,232,53,970,721,786,592,23,463,51,183,566,934,880,372,627,614,969,91,561,770,94,212,784,733,528,17,464,92,265,626,122,970,345,831,968,599,333,46,690,917,885,868,369,657,745,340,967,806,22,180,587,165,449,36,43,757,279,734,771,164,739,460,994,588,100,877,959,262,480,42,746,801,206,185,277,826,75,883,546,319,254,757,54,233,851,846,264,831,283,431,654,793,697,709,589,586,702,858,595,129,551,727,609,112,371,741,247,526,897,320,124,37,671,656,194,170,400,990,384,59,688,378,341,60,333,364,368,911,705,20,493,122,766,908,671,178,615,603,788,792,134,53,154,16,290,916,269,889,854,259,283,383,520,651,25,961,740,223,641,286,451,769,943,94,31,631,837,104,297,264,327,585,798,601,494,77,130,982,244,2,106,805,400,180,203,394,650,937,584,503,918,909,898,733,921,821,445,808,618,526,316,425,486,255,648,232,353,251,959,935,564,850,773,114,394,691,671,956,4,222,708,426,894,228,86,988,517,94,152,605,902,237,398,397,349,728,124,534,667,166,553,909,731,759,470,796,348,179,968,391,576,539,722,640,675,228,77,744,976,617,179,379,504,68,136,896,727,414,969,328,484,661,930,124,679,140,483,671,556,773,343,844,393,892,133,278,466,938,1,516,197,736,16,864,984,495,977,401,379}); } int main() { auto s = std::chrono::high_resolution_clock::now(); for (int i = 0; i < 1000; ++i) f(); auto e = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - s).count(); std::printf("%ld.%04ld ms\n", e / 1000000, e % 1000000); return 0; }