QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#540930#8936. Team Arrangementucup-team4508#RE 1ms6112kbC++141.3kb2024-08-31 18:09:402024-08-31 18:09:40

Judging History

This is the latest submission verdict.

  • [2024-08-31 18:09:40]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 6112kb
  • [2024-08-31 18:09:40]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define LL long long
struct segment{
	LL l,r;
}p[200005];
LL n,i,j,k,m,t,ans=-0x7fffffffffffffff,sum=0;
LL a[500005];
bool flag[65];
stack<LL> st,st1;
priority_queue<LL,vector<LL>,greater<LL> > h;
LL cmp(segment x,segment y){
	if(x.l==y.l) return x.r<y.r;
	else return x.l<y.l;
}
void dfs(LL x,LL y){
	if(x==n){
		while(!st.empty()){
			st1.push(st.top());
			st.pop();
		}
		while(!h.empty()) h.pop();
		LL now=1;
		bool flag=false;
		while(!st1.empty()){
			while(now<=n && p[now].l<=st1.top()){
				h.push(p[now].r);now++;
			}
			if(h.top()<st1.top()){
				flag=true;break;
			}
			LL len=h.size();
			if(len<st1.top()){
				flag=true;break;
			}
			st.push(st1.top());
			for(LL i=1;i<=st1.top();i++)
			  h.pop();
			st1.pop();
		}
		while(!st1.empty()){
			st.push(st1.top());st1.pop();
		}
		if(flag==false) ans=max(ans,sum);
		return ;
	}
	for(LL i=y;i<=n;i++){
		if(x+i>n) return ;
		st.push(i);sum+=a[i];dfs(x+i,i);
		st.pop();sum-=a[i];
	}
}
int main(){
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	  scanf("%lld%lld",&p[i].l,&p[i].r);
	sort(p+1,p+n+1,cmp);
	for(i=1;i<=n;i++)
	  scanf("%lld",&a[i]);
	dfs(0,1);
	if(ans==-0x7fffffffffffffff) printf("impossible");
	else printf("%lld",ans);
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6112kb

input:

3
2 3
1 2
2 2
4 5 100

output:

9

result:

ok single line: '9'

Test #2:

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

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

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

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

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

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

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

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: -100
Runtime Error

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:


result: