QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#826382#8936. Team ArrangementhotdogsellerWA 0ms3948kbC++141.6kb2024-12-22 09:41:152024-12-22 09:41:16

Judging History

This is the latest submission verdict.

  • [2024-12-22 09:41:16]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3948kb
  • [2024-12-22 09:41:15]
  • Submitted

answer

#include<bits/stdc++.h>

#define int long long
#define pii pair<int,int>
#define maxn 65
#define double long double
#define INF 1e18
#define mod 998244353

using namespace std;

inline int read(){
	int lre=0,f=1;
	char c=getchar();
	while(!isdigit(c)){
		if(c=='-'){
			f=-1;
		}
		c=getchar();
	}
	while(isdigit(c)){
		lre=(lre<<3)+(lre<<1)+(c-'0');
		c=getchar();
	}
	return lre*f;
}

struct node{
	int l,r;
}arr[maxn];

bool cmp(node x,node y){
	if(x.r==y.r){
		return x.l>y.l;
	}
	return x.r>y.r;
}

int n,res=-INF;
int l[maxn],r[maxn];
int w[maxn];

int d[maxn],cnt[maxn];//划分数
int a[maxn],b[maxn];

inline void calc(int m){
	for(register int i=1;i<=n;++i){
		a[i]=lower_bound(d+1,d+m+1,arr[i].l)-d;
		b[i]=upper_bound(d+1,d+m+1,arr[i].r)-d-1;
	}
	for(register int i=1;i<=m;++i)cnt[i]=d[i];
	int it=m;
	for(register int x=1;x<=n;++x){
		while(it>b[x]||(!cnt[it]))it--;
		if(it>=a[x])cnt[it]--;
		else return;
	}
	int lre=0;
	for(register int i=1;i<=m;++i)lre+=w[d[i]];
	res=max(res,lre);
}

void dfs(int x,int tmp){
//	cout<<"x="<<x<<endl;
//	if(tmp<0)return;
	if(!tmp){
		calc(x-1);
		return;
	}
	for(register int i=d[x-1];i<=tmp;i++){
		d[x]=i;
		dfs(x+1,tmp-i);
	}
}

signed main(){
	
	n=read();
	for(int i=1;i<=n;i++){
		arr[i].l=read();
		arr[i].r=read();
	}
	sort(arr+1,arr+n+1,cmp);
	for(int i=1;i<=n;i++)w[i]=read();
	d[0]=1;
	dfs(1,n);
	
	if(res==-INF){
		cout<<"impossible"<<endl;
	}else{
		printf("%lld\n",res);
	}
	
	return 0;
}
/*
 3
 2 3
 1 2
 2 2
 -100 -200 100000
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

input:

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

output:

-300

result:

ok single line: '-300'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3948kb

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:

5

result:

wrong answer 1st lines differ - expected: '6', found: '5'