QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#792505#8707. Jobsaas0 0ms3796kbC++141.3kb2024-11-29 10:57:532024-11-29 10:57:54

Judging History

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

  • [2024-11-29 10:57:54]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3796kb
  • [2024-11-29 10:57:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2010;
#define int long long
#define pii pair<int,int>
int x[N],p[N],n;vector<int>g[N];vector<pii>bl[N],q;
void dfs(int u){
//	cout<<u<<" frfr "<<endl;
	if(g[u].size()==0){
		if(x[u]>0)bl[u].push_back({0,x[u]});
		return ;
	}
	for(int i:g[u]){
		dfs(i);
		if(bl[i].size())
		for(pii j:bl[i]){
			bl[u].push_back(j);
		}
	}
	if(bl[u].size())
	sort(bl[u].begin(),bl[u].end());
	q.clear();
	if(x[u]>=0){
		if(!bl[u].size())bl[u].push_back({0,0});
		bl[u][0].first-=x[u];
		bl[u][0].first=max(bl[u][0].first,0ll);
		bl[u][0].second+=x[u];
	}else{
		int sig=0,sgg=0;
		int end=0;
		for(int i=0;i<bl[u].size();i++){
			sig+=bl[u][i].first,sgg+=bl[u][i].second;
			if(sgg+x[u]>0){
				end=i+1;q.push_back({sig-x[i],sgg+x[u]});
				break;
			}
		}
		for(int j=end;j<bl[u].size();j++){
			q.push_back(bl[u][j]);
		}
		bl[u]=q;
	}
	sort(bl[u].begin(),bl[u].end());
/*	for(int i=0;i<bl[u].size();i++){
		cout<<u<<" "<<i<<" "<<bl[u][i].first<<" "<<bl[u][i].second<<endl;
	}*/
}
int pres,s;
signed main(){
	cin>>n>>s;pres=s;
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&x[i],&p[i]);
		g[p[i]].push_back(i);
	}
	dfs(0);
	for(int i=0;i<bl[0].size();i++){
		pii cur=bl[0][i];
		if(cur.first>s)break;
		s+=cur.second;
	}
	cout<<s-pres<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

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:


result:


Subtask #2:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 0ms
memory: 3796kb

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:

33

result:

wrong answer 1st lines differ - expected: '16', found: '33'

Subtask #3:

score: 0
Runtime Error

Test #42:

score: 0
Runtime Error

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:


result:


Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%