QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607357#8936. Team Arrangementliguo#TL 1ms8068kbC++201.9kb2024-10-03 14:47:312024-10-03 14:47:31

Judging History

This is the latest submission verdict.

  • [2024-10-03 14:47:31]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 8068kb
  • [2024-10-03 14:47:31]
  • Submitted

answer

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
const int maxn=3e6+10;
const int mod=1e9+7;
long long read(){
	long long ans=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
	 	c=getchar();
	}
	while(c>='0'&&c<='9'){
	 	ans=ans*10+c-'0';
	 	c=getchar();
	}
	return ans*f;
}
long long n,m,z,t;
struct noe{
	int l,r;
}h[maxn];
long long c[maxn];
bool cmp(noe a,noe b){
	return a.r<b.r;
}
int fl=0,zhan[maxn],top=0;
long long ans=-1e9;
struct node{
	int l,r;
	bool operator <(const node &a)const{
		return l>a.l;
	}
};
priority_queue<node>q;
struct nde{
	int l,r;
	bool operator <(const nde &a)const{
		return r<a.r;
	}
};
priority_queue<nde>qq;
void check(int x,int y){
	if(!x){
		while(!q.empty()) q.pop();
		while(!qq.empty()) qq.pop();
		for(int i=1;i<=n;i++){
			nde tmp;
			tmp.l=h[i].l;
			tmp.r=h[i].r;
			qq.push(tmp);
		}
		long long sum=0;
		for(int i=1;i<=top;i++){
			int sm=zhan[i];
			while(!qq.empty()&&qq.top().r>=zhan[i]){
				nde tmp=qq.top();
				qq.pop();
				node pmt;
				pmt.l=tmp.l;
				pmt.r=tmp.r;
				q.push(pmt);
				sm--;
			}
			//printf("*%d %d",sm,i);
			if(sm>0) return;
		//	printf("==%d\n",i);
			while(sm<0){
				sm++;
				node pmt=q.top();
				q.pop();
				nde tmp;
				tmp.l=pmt.l;
				tmp.r=pmt.r;
				qq.push(tmp);
			}
			//printf("%d %d %d\n",q.top().l,q.top().r,zhan[i]);
			while(!q.empty()){
				node pmt=q.top();
				q.pop();
				if(pmt.l>zhan[i]) return;
			}
			sum+=c[zhan[i]];
		}
		ans=max(ans,sum);
		fl=1;
		return;
	}
	for(int j=min(y,x);j>=1;j--){
		zhan[++top]=j;
		check(x-j,j);
		top--;
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		h[i].l=read();
		h[i].r=read();
	}
	for(int i=1;i<=n;i++) scanf(" %lld",&c[i]);
	check(n,n);
	if(fl) printf("%lld",ans);
	else printf("impossible");
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 8012kb

input:

3
2 3
1 2
2 2
4 5 100

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 0ms
memory: 8068kb

input:

3
1 3
3 3
2 3
1 1 100

output:

100

result:

ok single line: '100'

Test #3:

score: 0
Accepted
time: 1ms
memory: 8000kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7960kb

input:

3
2 3
1 2
2 2
-100 -200 100000

output:

-300

result:

ok single line: '-300'

Test #5:

score: 0
Accepted
time: 1ms
memory: 7876kb

input:

9
1 4
2 5
3 4
1 5
1 1
2 5
3 5
1 3
1 1
1 1 1 1 1 1 1 1 1

output:

6

result:

ok single line: '6'

Test #6:

score: 0
Accepted
time: 0ms
memory: 7992kb

input:

14
3 3
1 2
2 3
2 3
2 3
1 1
2 3
1 3
3 3
1 3
1 3
1 2
2 3
1 3
-9807452 -9610069 4156341 2862447 6969109 -7245265 -2653530 -5655094 6467527 -6872459 3971784 7312155 9766298 -2719573

output:

-16558567

result:

ok single line: '-16558567'

Test #7:

score: 0
Accepted
time: 1ms
memory: 8016kb

input:

14
1 2
1 4
2 3
3 5
4 5
2 5
2 4
2 4
1 2
3 4
1 5
2 4
1 1
4 5
-13763 -7354207 1096407 -9063321 -4824546 -6275546 1258145 -5272834 -8631107 3581157 2320771 -7714508 8446625 -6816167

output:

-2673021

result:

ok single line: '-2673021'

Test #8:

score: 0
Accepted
time: 1ms
memory: 7940kb

input:

14
2 3
4 4
1 7
3 6
3 4
1 1
1 4
4 7
3 7
1 7
2 3
6 6
1 1
3 6
2923142 1686477 640352 2848353 9202543 -4441381 4866381 -3610520 8124124 -1372894 1111310 -7538627 466143 9937961

output:

5939733

result:

ok single line: '5939733'

Test #9:

score: 0
Accepted
time: 1ms
memory: 7936kb

input:

14
1 7
1 2
8 8
1 1
7 8
6 9
7 8
1 4
6 9
3 3
1 1
3 7
5 8
4 8
-7139089 6365816 -9893288 5936146 -2803918 -4961415 1495365 -2564851 -2630365 -8608883 5813455 -4005459 -8844054 6703783

output:

impossible

result:

ok single line: 'impossible'

Test #10:

score: 0
Accepted
time: 1ms
memory: 8000kb

input:

14
6 13
3 7
2 13
6 8
4 5
12 13
3 10
4 11
2 14
3 4
5 13
10 14
10 14
3 12
-8599727 -1496394 855072 -7439122 -5170228 8009298 -250221 5841035 2949765 7166358 -3516548 -6851737 8173765 -917122

output:

impossible

result:

ok single line: 'impossible'

Test #11:

score: -100
Time Limit Exceeded

input:

60
21 34
13 34
48 49
31 42
5 6
16 30
1 25
35 37
3 14
3 32
25 54
2 41
24 44
27 52
26 55
8 35
31 47
41 42
4 35
53 59
13 19
11 51
36 48
5 59
40 44
28 50
5 51
37 53
50 60
14 50
22 58
20 50
20 21
5 20
19 55
5 45
19 35
7 29
5 53
25 33
19 51
37 41
13 29
12 24
13 40
10 22
1 5
22 32
14 42
11 41
16 60
35 43
3...

output:


result: