QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#821302#9331. Maximize the MinimumcwfxlhWA 157ms9768kbC++141.5kb2024-12-19 15:01:512024-12-19 15:01:51

Judging History

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

  • [2024-12-19 15:01:51]
  • 评测
  • 测评结果:WA
  • 用时:157ms
  • 内存:9768kb
  • [2024-12-19 15:01:51]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,m,s,dp[500003][2],nxt[500003][2],nxt2[500003],lst[2],lft,rgt,mid,sump;
pair<pair<int,int>,int>p[500003];
void upd(int &x,int y){x=max(x,y);return;}
bool chk(int X){
	lst[0]=lst[1]=0;
	for(int i=n,j=n+1;i;i--){
		while(j-1>i&&p[j-1].first.first-p[i].first.first>=X){
			j--;
			lst[p[j].first.second]=j;
		}
		nxt2[i]=lst[p[i].first.second^1];
	}
	for(int i=1;i<=n;i++)dp[i][0]=p[i].second,dp[i][1]=-sump;
	for(int i=1;i<=n;i++){
		if(nxt[i][p[i].first.second]){
			upd(dp[nxt[i][p[i].first.second]][0],dp[i][0]+p[nxt[i][p[i].first.second]].second);
			upd(dp[nxt[i][p[i].first.second]][1],dp[i][1]+p[nxt[i][p[i].first.second]].second);
		}
		if(nxt2[i]){
			upd(dp[nxt2[i]][1],dp[i][0]+p[nxt2[i]].second);
			upd(dp[nxt2[i]][1],dp[i][1]+p[nxt2[i]].second);
		}
	}
	for(int i=1;i<=n;i++)if(sump-dp[i][1]<=s)return true;
	return false;
}
void sol(){
	sump=0;
	cin>>n>>m>>s;
	for(int i=1;i<=n+m;i++){
		cin>>p[i].first.first;
		p[i].first.second=(i>n);
	}
	for(int i=1;i<=n+m;i++)cin>>p[i].second;
	for(int i=1;i<=n+m;i++)sump+=p[i].second;
	n+=m;
	sort(p+1,p+n+1);
	lst[0]=lst[1]=0;
	for(int i=n;i;i--){
		nxt[i][0]=lst[0];
		nxt[i][1]=lst[1];
		lst[p[i].first.second]=i;
	}
	lft=0;
	rgt=1000000000000ll;
	while(lft<rgt){
		mid=((lft+rgt)/2)+1;
		if(chk(mid))lft=mid;
		else rgt=mid-1;
	}
	cout<<lft<<'\n';
	return;
}
signed main(){
	ios::sync_with_stdio(false);
	cin>>T;
	while(T--)sol();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9700kb

input:

2
1 4 10
15
1 6 9 13
8
3 1 2 4
5 4 4
-1 5 3 2 -4
-7 8 6 2
2 3 1 1 2
3 1 1 1

output:

14
3

result:

ok 2 number(s): "14 3"

Test #2:

score: 0
Accepted
time: 116ms
memory: 9700kb

input:

40000
5 3 4
1 -5 -2 -5 4
-3 -4 -4
4 8 2 4 7
5 3 7
5 3 6
-4 -7 -4 -1 -7
-4 -4 -2
6 8 3 4 5
5 3 5
5 3 6
-1 2 3 -4 -1
-1 -2 -3
8 3 4 3 2
2 5 2
5 3 4
-5 -2 3 -1 2
-3 0 -2
6 5 1 1 6
7 8 7
5 3 4
0 0 1 -4 -2
-4 -4 -3
7 7 5 8 3
8 2 4
5 3 4
0 -4 -1 1 -6
-2 -5 -4
7 4 5 7 3
5 5 2
5 3 6
-4 -3 0 2 -4
-5 -4 -4
6 ...

output:

1
0
1
0
0
1
0
0
0
1
0
1
1
2
0
0
0
0
1
1
1
0
0
0
0
3
1
1
0
0
0
1
1
2
1
0
1
1
1
1
0
1
1
2
2
4
1
1
1
0
0
1
0
1
1
2
0
0
0
2
1
1
0
0
1
2
1
1
3
0
1
1
4
2
0
0
1
1
0
2
0
3
1
0
1
1
0
0
0
1
1
2
0
1
0
1
0
0
1
1
1
1
1
0
2
2
1
1
0
1
1
1
1
1
0
0
2
0
2
1
0
1
0
1
0
0
0
0
0
0
0
1
0
0
1
1
1
2
0
2
0
2
2
0
0
1
0
1
2
1
...

result:

ok 40000 numbers

Test #3:

score: 0
Accepted
time: 118ms
memory: 9768kb

input:

20000
10 10 139
6 -2 14 6 2 10 -2 -1 5 -4
10 8 35 28 40 35 18 20 3 -5
7 84 54 63 48 28 17 11 16 38
64 58 2 80 65 42 92 69 26 19
10 10 137
2 14 10 6 17 -3 13 -6 14 0
17 -5 1 6 -5 -5 6 1 15 10
5 25 64 86 89 86 89 42 47 53
28 55 56 32 38 46 24 20 9 56
10 10 121
-1 9 11 -2 11 10 -2 12 5 3
2 27 33 11 26 ...

output:

4
0
0
2
5
2
1
2
1
14
2
3
1
10
1
2
1
2
1
3
0
2
2
0
2
1
6
1
1
2
3
1
1
0
5
2
2
3
1
1
2
5
9
1
1
2
2
1
0
1
1
2
0
1
1
3
4
2
3
1
1
3
2
6
0
0
1
1
2
2
1
1
2
2
2
0
1
1
2
0
2
1
2
2
0
1
1
2
1
1
1
1
1
0
1
5
4
1
1
2
6
3
1
1
2
9
4
3
5
13
1
1
2
1
1
3
1
1
0
1
2
1
1
2
0
2
1
1
2
1
6
4
0
0
11
4
1
2
9
1
1
1
2
0
1
1
1
0
...

result:

ok 20000 numbers

Test #4:

score: 0
Accepted
time: 135ms
memory: 9708kb

input:

20000
10 10 266
2 10 -2 7 15 12 12 3 14 15
3 35 -9 -5 12 27 19 4 -9 -10
90 82 18 78 78 98 25 89 92 9
63 42 63 43 64 33 30 50 11 99
10 10 222
10 4 -2 -4 8 -6 -6 8 0 3
8 18 26 24 0 11 -5 25 20 8
26 39 99 100 22 56 51 29 59 45
58 50 54 37 67 88 79 2 52 32
10 10 255
2 -5 6 9 -3 12 -2 -2 15 -6
19 -3 -1 2...

output:

7
2
3
6
2
3
7
9
8
13
5
7
7
3
9
30
12
14
13
2
13
6
6
2
1
3
7
11
3
6
1
2
5
14
2
10
2
1
7
13
15
15
4
14
3
4
6
5
23
2
4
1
2
7
0
3
4
2
2
2
21
8
3
18
6
19
5
4
2
3
2
2
2
6
8
9
3
2
3
25
9
4
5
5
14
4
1
5
12
31
3
1
13
6
4
7
5
8
5
17
0
1
13
3
7
3
2
3
22
2
7
25
2
5
10
22
13
5
4
4
2
19
3
5
18
6
2
5
1
6
1
3
4
2
2...

result:

ok 20000 numbers

Test #5:

score: 0
Accepted
time: 131ms
memory: 9752kb

input:

20000
10 10 5
-4 24 0 20 11 16 18 8 4 15
19 2 17 10 -4 -7 14 14 -5 14
1 13 50 59 81 92 8 69 28 35
79 18 58 86 60 38 11 31 70 61
10 10 5
12 4 18 20 4 1 15 8 -6 -2
2 2 10 -6 8 8 -4 9 -5 14
18 100 83 75 46 55 78 28 72 36
46 51 82 5 75 90 38 93 8 53
10 10 6
13 8 7 2 -1 10 -1 -4 17 5
9 28 12 12 35 4 41 2...

output:

1
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
1
1
1
0
0
0
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
1
1
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
1
0
0
0
...

result:

ok 20000 numbers

Test #6:

score: 0
Accepted
time: 157ms
memory: 9764kb

input:

20000
10 10 153
-999999978 -999999983 -999999973 -999999986 -999999967 -999999986 -999999974 -999999998 -999999958 -999999991
-999999943 -999999981 -999999978 -999999946 -999999968 -999999990 -999999979 -999999990 -999999962 -999999952
36 33 6 20 20 10 4 32 31 34
23 20 17 30 38 4 7 38 8 36
10 10 115...

output:

10
6
9
9
6
1
4
8
14
4
2
18
18
13
23
12
9
13
16
15
5
7
2
15
5
5
2
10
7
5
3
4
6
13
2
10
4
2
6
5
4
23
12
8
18
16
14
2
7
10
26
23
9
8
14
26
4
3
5
3
4
11
6
7
23
6
12
19
2
6
35
4
10
14
5
16
40
42
8
27
12
19
20
11
27
21
3
6
4
5
4
19
6
5
28
14
21
3
21
14
3
7
30
14
10
4
3
14
11
23
2
6
2
11
6
10
4
5
25
5
7
16...

result:

ok 20000 numbers

Test #7:

score: 0
Accepted
time: 119ms
memory: 9768kb

input:

20000
10 10 44
320 257 532 97 331 455 189 428 598 437
4200 1266 74 2885 2554 2581 2060 3561 1065 3662
3 2 10 19 4 7 8 10 2 7
11 6 19 3 10 15 20 5 5 11
10 10 43
108 198 244 354 268 145 48 185 1 245
2098 572 1250 3045 4489 4315 488 757 2399 3842
9 12 2 2 1 8 9 20 11 7
11 8 5 16 12 14 3 14 4 13
10 10 4...

output:

1605
2131
3229
1251
2425
498
1542
2012
2091
1897
829
164
2977
2360
1421
1021
1839
1748
1317
453
955
1700
2702
2097
3684
2052
1811
1208
986
5394
1974
3858
2871
1035
4846
2827
1629
2588
2215
2166
2245
1109
1397
1756
3122
3203
3119
1385
2243
1437
4042
2971
816
2619
2348
152
2170
1223
1002
1591
6167
412...

result:

ok 20000 numbers

Test #8:

score: -100
Wrong Answer
time: 118ms
memory: 9764kb

input:

20000
10 10 9906966020564
1747 94 4537 5180 2516 3614 888 2807 4548 2401
2888 5381 4360 466 1441 5477 2048 4382 3874 3973
187573830006 84900724601 2818831443 37850023841 31710775770 124858816256 38802795362 102346831882 99252379848 81629754358
6892399729 180038375513 17772942222 36958278416 17732975...

output:

1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
100000...

result:

wrong answer 1st numbers differ - expected: '5383', found: '1000000000000'