QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#419429#8707. Jobspaul20080 236ms101452kbC++141.2kb2024-05-23 22:02:122024-05-23 22:02:12

Judging History

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

  • [2024-05-23 22:02:12]
  • 评测
  • 测评结果:0
  • 用时:236ms
  • 内存:101452kb
  • [2024-05-23 22:02:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N=3e5+5;

int p[N], a[N];
vector <int> g[N];
set <pair<int,int> > s[N];

void dfs(int x)
{
	for(auto to:g[x])
	{
		dfs(to);
		if(s[x].size()<s[to].size())
			swap(s[x],s[to]);

		for(auto p:s[to])
			s[x].insert(p);

		s[to].clear();
	}

	if(a[x]>0)
		s[x].insert(make_pair(0,a[x]));
	else
	{
		int now=-a[x], sum=a[x];
		while(sum<=0 && s[x].size())
		{
			sum += s[x].begin()->second;
			now = max(s[x].begin()->first-sum,now);
			s[x].erase(s[x].begin());
		}

		if(sum<=0)
			return;

		auto ed=s[x].end();
		for(auto it=s[x].begin();it!=s[x].end();it++)
			if(it->first>now)
			{
				ed=it;
				break;
			}
			else
				sum += it->second;

		s[x].erase(s[x].begin(),ed);
		s[x].insert(make_pair(now,sum));
	}
}

signed main()
{
	int n,start;
	cin >> n >> start;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i+1],&p[i+1]);
		p[i+1]++;
	}
	n++;

	for(int i=2;i<=n;i++)
		g[p[i]].push_back(i);

	dfs(1);

	int ans=0;
	for(auto x:s[1])
		if(start>=x.first)
			start += x.second, ans += x.second;
	printf("%lld\n",ans);
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 11
Accepted
time: 236ms
memory: 47196kb

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: 208ms
memory: 46172kb

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: 182ms
memory: 45500kb

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: 11
Accepted
time: 107ms
memory: 61132kb

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:

963990158

result:

ok single line: '963990158'

Test #5:

score: 11
Accepted
time: 110ms
memory: 72164kb

input:

294609 1000000000000000000
-14859 0
-6241 0
28010 1
-35056 3
-18753 3
29895 5
37233 4
-45266 7
15101 2
46739 8
-42054 7
-47262 10
-47937 10
44830 11
59665 13
48681 12
-49712 15
53835 17
-61975 15
67471 19
-66656 20
-73226 20
78369 21
80156 22
-92090 24
97049 25
-95094 26
-85272 24
100554 27
89857 28...

output:

931886923

result:

ok single line: '931886923'

Test #6:

score: 0
Wrong Answer
time: 126ms
memory: 38228kb

input:

189644 1000000000000000000
-98837 0
119840 1
-99489 2
-76401 0
128492 3
116250 4
-96744 6
-99996 5
133521 8
-99952 5
135918 10
-99998 9
-99991 11
112238 12
-585552 14
-123819 14
601536 15
165067 16
143777 13
-1401938 18
114098 7
-99847 21
-846458 17
-552575 18
141499 22
589263 24
-99993 25
-152653 1...

output:

552689868

result:

wrong answer 1st lines differ - expected: '552691392', found: '552689868'

Subtask #2:

score: 0
Wrong Answer

Test #14:

score: 14
Accepted
time: 4ms
memory: 28480kb

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: 3ms
memory: 28976kb

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: 3ms
memory: 27456kb

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: 0ms
memory: 29396kb

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: 4ms
memory: 28784kb

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: 0ms
memory: 28676kb

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: 2ms
memory: 27972kb

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: 28100kb

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: 28132kb

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: 7ms
memory: 27196kb

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
Wrong Answer

Test #42:

score: 15
Accepted
time: 126ms
memory: 48416kb

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: 104ms
memory: 47564kb

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: 116ms
memory: 44432kb

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
Wrong Answer
time: 82ms
memory: 101452kb

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:

27929

result:

wrong answer 1st lines differ - expected: '546593', found: '27929'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%