QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630985#8936. Team ArrangementFHQY#WA 1ms3956kbC++201.0kb2024-10-11 21:14:562024-10-11 21:15:01

Judging History

This is the latest submission verdict.

  • [2024-10-11 21:15:01]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3956kb
  • [2024-10-11 21:14:56]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N=61;
struct seg{int l,r;}a[N];
int b[N],w[N],m,n;
int ans=-2e9;
bool cmp(seg a,seg b){
	if(a.r!=b.r)return a.r>b.r;
	else return a.l>b.l;
}
bool check(){
	multiset<int>s;
	for(int i=1;i<=m;i++)
		for(int j=1;j<=b[i];j++)s.insert(b[i]);
	for(int i=1;i<=n;i++){
		auto now=s.lower_bound(a[i].l);
		if(now==s.end())return 0;
		if((*now)>a[i].r)return 0;
		s.erase(now);
	}
	return 1;
}
void out(){
	printf("the number : %d\n",m);
	for(int i=1;i<=m;i++)
		printf("%d ",b[i]);
	puts("");
}
void dfs(int las,int rm){
	if(rm==0){
//		out();
		int tmp=0;
		for(int i=1;i<=m;i++)
			tmp+=w[b[i]];
		if(tmp<=ans)return;
		if(check())ans=tmp;
		return;
	}
	for(int i=las;i>=1;i--){
		b[++m]=i;
		if(rm-i>=0)dfs(i,rm-i);
		--m;
	}
}
int main(){
	scanf("%d",&n);	
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].l,&a[i].r);
	for(int i=1;i<=n;i++)
		scanf("%d",&w[i]);
	sort(a+1,a+n+1,cmp);
	dfs(n,n);
	if(ans==-2e9)puts("impossible");
	else cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

3
1 3
3 3
2 3
1 1 100

output:

100

result:

ok single line: '100'

Test #3:

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

input:

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

output:

-300

result:

ok single line: '-300'

Test #5:

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

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: -100
Wrong Answer
time: 1ms
memory: 3672kb

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:

-83715961

result:

wrong answer 1st lines differ - expected: '-16558567', found: '-83715961'