QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#429663 | #8707. Jobs | piokemon | 0 | 551ms | 302284kb | C++17 | 2.1kb | 2024-06-02 19:02:39 | 2024-06-02 19:02:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
constexpr int N = 3e5;
int par[N+9];
ll w[N+9];
vector<int> dzieci[N+9];
multiset<pair<ll,ll>> kol[N+9];
// min,zysk
int gdzie[N+9];
vector<pair<ll,ll>> kolejki[N+9];
int p[N+9];
void rek(int v){
gdzie[v]=v;
for (int x:dzieci[v]){
rek(x);
if (kol[x].size()>kol[gdzie[v]].size()){
gdzie[v]=x;
}
}
for (int x:dzieci[v]){
if (x!=gdzie[v]){
for (pair<ll,ll>y:kol[gdzie[x]])kol[gdzie[v]].insert(y);
}
}
pair<ll,ll> nowe = {-w[v],w[v]};
while(nowe.second<0 && !kol[gdzie[v]].empty()){
pair<ll,ll> temp=*kol[gdzie[v]].begin(); kol[gdzie[v]].erase(kol[gdzie[v]].begin());
nowe = {max(nowe.first,temp.first),nowe.second+temp.second};
}
if (nowe.second>=0){
while(!kol[gdzie[v]].empty() && (*kol[gdzie[v]].begin()).first<nowe.first){
nowe.second += (*kol[gdzie[v]].begin()).second;
kol[gdzie[v]].erase(kol[gdzie[v]].begin());
}
kol[gdzie[v]].insert(nowe);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
ll s;
cin >> n>> s;
for (int x=1;x<=n;x++){
cin >> w[x] >> par[x];
dzieci[par[x]].push_back(x);
}
// w dzieci[0] mam wszystkie poczatki kolejek
int nr=1;
priority_queue<pair<ll,int>> pocz;
for (int x:dzieci[0]){
rek(x);
if (kol[gdzie[x]].empty())continue;
for (pair<ll,ll> y:kol[gdzie[x]])kolejki[nr].push_back(y);
pocz.push({-kolejki[nr][0].first,nr});
par[nr]=0;
nr++;
}
ll odp=0;
while(!pocz.empty()){
pair<ll,int> ter=pocz.top();pocz.pop(); ter.first=-ter.first;
if (s<ter.first)break;
s+=kolejki[ter.second][p[ter.second]].second;
odp+=kolejki[ter.second][p[ter.second]].second;
p[ter.second]++;
if (p[ter.second]<kolejki[ter.second].size())pocz.push({-kolejki[ter.second][p[ter.second]].first,ter.second});
}
cout << odp << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 11
Accepted
time: 551ms
memory: 302284kb
input:
299955 1000000000000000000 -2 0 10 1 -9 2 14 3 -11 4 17 5 -21 6 22 7 -22 8 23 9 -41 10 -89 10 49 11 99 12 -120 14 -23 8 130 15 24 16 -51 13 55 19 -144 20 -24 18 -30 18 -54 13 64 24 -105 14 145 21 -60 20 -183 25 61 28 -334 30 340 31 111 26 -135 33 -184 33 191 35 -231 17 -505 27 -570 32 -257 25 238 37...
output:
551168
result:
ok single line: '551168'
Test #2:
score: 11
Accepted
time: 156ms
memory: 78236kb
input:
299932 1000000000000000000 -26 0 -38 0 -521 0 -567 0 -569 0 -235 0 -294 0 -134 0 144 8 -177 0 -458 0 -9675 9 296 7 -15 0 34 1 -21349 9 -15643 9 -280 0 -445 15 -13253 13 -7497 15 -12328 15 -3131 15 7498 21 -172566 24 -14287 13 -24726 13 -1 0 -12603 13 -14221 13 -401 0 -4105 13 -2872 15 -1264 9 -5095 ...
output:
797403
result:
ok single line: '797403'
Test #3:
score: 11
Accepted
time: 128ms
memory: 61716kb
input:
299978 1000000000000000000 -319087 0 -397343 0 -746276 0 -123466 0 -27323 0 -462189 0 -44293 0 -157047 0 -492663 0 -471747 0 -214986 0 -276045 0 -134544 0 -245003 0 -564286 0 -100579 0 -128044 0 -725767 0 -317957 0 -515861 0 -209544 0 -152961 0 -275236 0 -499829 0 -609630 0 -439399 0 -61718 0 -80829...
output:
822051
result:
ok single line: '822051'
Test #4:
score: 0
Time Limit Exceeded
input:
295612 1000000000000000000 -59435628 0 -94130 0 98375 2 -101252 3 -376825783 3 376834010 5 59435737 1 110079 4 -107471 8 -142894643 8 123353 9 -125578 11 -205705873 11 142895079 10 205719702 13 128238 12 -563917506 16 563929915 17 -129566 16 139278 19 -134538 20 -146413129 20 145442 21 -150271 23 15...
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #14:
score: 14
Accepted
time: 0ms
memory: 34484kb
input:
17 5 -3 0 4 1 -4 2 9 3 -5 4 13 5 -6 6 8 7 -23 8 28 9 -26 10 31 11 -28 12 33 13 -39 14 41 15 -7 16
output:
16
result:
ok single line: '16'
Test #15:
score: 14
Accepted
time: 4ms
memory: 34540kb
input:
17 1 -14 0 21 1 -15 2 16 3 -22 4 29 5 -32 6 34 7 -33 8 35 9 -10 10 -1 0 6 12 -3 13 5 14 -16 15 22 16
output:
7
result:
ok single line: '7'
Test #16:
score: 14
Accepted
time: 0ms
memory: 36656kb
input:
17 4 -4 0 12 1 -5 0 8 3 -13 0 17 5 -38 6 39 7 -3 8 -6 0 12 10 -29 11 35 12 -32 13 39 14 -24 0 31 16
output:
42
result:
ok single line: '42'
Test #17:
score: 14
Accepted
time: 6ms
memory: 36792kb
input:
1998 100000 -119974094 0 120949782 1 -148267915 2 149258545 3 -353200332 4 353781482 5 -409351160 0 410180396 7 -405293412 0 405638769 9 -491561775 0 492142804 11 -38208552 0 38786890 13 -188326000 0 188960234 15 -294174444 16 294530806 17 -430597876 18 431035538 19 -487343715 20 487438668 21 -17231...
output:
33581034
result:
ok single line: '33581034'
Test #18:
score: 14
Accepted
time: 39ms
memory: 58764kb
input:
1996 100000 -59755 0 151138 1 -174993 2 255152 3 -257624 4 322787 5 -293552 6 392535 7 -350940 8 418275 9 -487611 10 515476 11 -507579 12 556319 13 -549422 14 556127 15 -584293 16 638017 17 -613793 18 628801 19 -653479 20 704157 21 -695266 22 732277 23 -727516 24 792824 25 -781086 26 819574 27 -8098...
output:
23781881
result:
ok single line: '23781881'
Test #19:
score: 14
Accepted
time: 19ms
memory: 49984kb
input:
1996 83074 -104912 0 157516 1 -226832 2 244272 3 -236577 4 251249 5 -345494 6 411376 7 -527443 8 582958 9 -583787 10 665523 11 -681920 12 727305 13 -730788 14 757169 15 -844569 16 893388 17 -871493 18 916618 19 -1019572 20 1118628 21 -1135127 22 1163326 23 -1294857 24 1367717 25 -1345986 26 1391230 ...
output:
48888408
result:
ok single line: '48888408'
Test #20:
score: 14
Accepted
time: 3ms
memory: 39060kb
input:
1997 392026 -368613 0 553533 1 -8120957 2 8333895 3 -7985911 4 3312802 5 4435825 6 18517 7 -1014196 8 -10212556 9 11612664 10 -13466519 11 14039962 12 -21043407 13 21174643 14 -21449184 15 22266444 16 -31562006 17 31769754 18 -33458430 19 33563104 20 -34071074 21 34188004 22 -34242437 23 34307017 24...
output:
423307544
result:
ok single line: '423307544'
Test #21:
score: 14
Accepted
time: 4ms
memory: 37424kb
input:
1998 3670 -4263584 0 4318213 1 -4766861 2 4793818 3 -6021755 4 6028915 5 -10981412 6 11043466 7 -14917467 8 14928380 9 -18108504 10 18125244 11 -23575827 12 23586895 13 -24056708 14 24132173 15 -25452036 16 25510395 17 -36702348 18 36770088 19 -37159186 20 37165482 21 -38084372 22 38124010 23 -40075...
output:
30157547
result:
ok single line: '30157547'
Test #22:
score: 14
Accepted
time: 3ms
memory: 35064kb
input:
1996 100000 -47319305 0 47364706 1 -13725945 0 13780218 3 -24704817 4 24745187 5 -44323181 0 44421117 7 -5595173 0 5676261 9 -16802773 10 16822863 11 -8972006 0 8976861 13 -4882300 0 4967180 15 -19353494 16 19362861 17 -7345443 0 7410858 19 -21922402 20 21943524 21 -28082838 22 28092936 23 -41738649...
output:
28784257
result:
ok single line: '28784257'
Test #23:
score: 0
Wrong Answer
time: 3ms
memory: 36564kb
input:
1996 954331 -246525934 0 246824973 1 -171768374 0 171931727 3 -277027442 4 277822284 5 -309469868 6 309597847 7 -285885388 8 -122289714 9 408353344 10 -449147475 11 449304397 12 -99137909 0 99891216 14 -388030661 15 388769528 16 -441565178 17 441709887 18 -53104970 0 53516386 20 -153117624 21 153153...
output:
470851941
result:
wrong answer 1st lines differ - expected: '39368059', found: '470851941'
Subtask #3:
score: 0
Time Limit Exceeded
Test #42:
score: 15
Accepted
time: 277ms
memory: 288316kb
input:
300000 0 -1677 0 1678 1 -3010 2 3011 3 -8141 4 8142 5 -11233 6 11234 7 -14400 8 14401 9 -17045 10 17046 11 -19521 12 19522 13 -23178 14 23179 15 -26907 16 26908 17 -28884 18 28885 19 -30742 20 30743 21 -35957 22 35958 23 -38436 24 38437 25 -39739 26 39740 27 -42432 28 42433 29 -47866 30 47867 31 -48...
output:
150000
result:
ok single line: '150000'
Test #43:
score: 15
Accepted
time: 81ms
memory: 77676kb
input:
300000 0 -2707 0 2708 1 -35703 2 35704 3 -87028 4 87029 5 -90666 6 90667 7 -144441 8 144442 9 -13210 0 13211 11 -54700 12 54701 13 -65742 14 65743 15 -118284 16 118285 17 -128694 18 128695 19 -7111 0 7112 21 -57902 22 57903 23 -79725 24 79726 25 -110281 26 110282 27 -124571 28 124572 29 -18852 0 188...
output:
150000
result:
ok single line: '150000'
Test #44:
score: 15
Accepted
time: 72ms
memory: 58364kb
input:
300000 0 -62936 0 62937 1 -137762 0 137763 3 -73582 0 73583 5 -66183 0 66184 7 -75047 0 75048 9 -43684 0 43685 11 -2721 0 2722 13 -111595 0 111596 15 -61005 0 61006 17 -85734 0 85735 19 -87099 0 87100 21 -140862 0 140863 23 -12218 0 12219 25 -68482 0 68483 27 -40203 0 40204 29 -34323 0 34324 31 -374...
output:
150000
result:
ok single line: '150000'
Test #45:
score: 0
Time Limit Exceeded
input:
299994 8 -3 0 11 1 -9 2 15 3 -21 4 25 5 -23 6 33 7 -33 8 40 9 -37 10 44 11 -45 12 48 13 -52 14 60 15 -61 16 65 17 -63 18 66 19 -66 20 69 21 -70 22 75 23 -74 24 77 25 -78 26 88 27 -84 28 92 29 -97 30 106 31 -102 32 104 33 -108 34 112 35 -110 36 116 37 -116 38 121 39 -119 40 127 41 -125 42 131 43 -136...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%