QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630991 | #8936. Team Arrangement | FHQY# | WA | 0ms | 3960kb | C++20 | 1.0kb | 2024-10-11 21:16:12 | 2024-10-11 21:16:14 |
Judging History
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--)
if(rm-i>=0){
b[++m]=i;
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: 3960kb
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: 3684kb
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: 3736kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
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: 3660kb
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: 0ms
memory: 3596kb
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'