QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#614387 | #8936. Team Arrangement | ucup-team4975 | WA | 0ms | 3892kb | C++23 | 1.4kb | 2024-10-05 16:17:16 | 2024-10-05 16:17:27 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include<map>
#include<queue>
#include<vector>
#include<fstream>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int N=70;
typedef long long ll;
int n;
ll ans,w[N];
vector<int>c;
priority_queue<int,vector<int>,greater<int> >q;
struct Node{
int l,r;
inline bool operator<(const Node that){
return l==that.l?r<that.r:l<that.l;
}
}a[N];
inline bool valid()
{
while(q.size())q.pop();
int pos=0;
for(auto x:c)
{
while(pos+1<=n&&a[pos+1].l<=x)
q.push(a[++pos].r);
while(q.size()&&q.top()<x)q.pop();
if(q.size()<x)return 0;
for(int i=1;i<=x;i++)
q.pop();
}
return 1;
}
inline void dfs(int pos,int lst)
{
if(!pos)
{
//for(auto x:c)
// cout<<x<<" ";
//cout<<endl;
if(valid())
{
ll posans=0;
for(auto x:c)
posans+=w[x];
ans=max(ans,posans);
}
return;
}
if(pos<lst)return;
for(int i=lst;;i++)
{
if((pos-i)&&pos-i<i)break;
c.push_back(i);
dfs(pos-i,i);
c.pop_back();
}
}
signed main()
{
ans=-1000000000000000000ll;
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("%lld",&w[i]);
sort(a+1,a+1+n);
dfs(n,1);
c.clear();
c.push_back(n);
if(valid())ans=max(ans,w[n]);
if(ans==-1000000000000000000ll)
puts("impossible");
else printf("%lld\n",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
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: 3892kb
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: 3688kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3872kb
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: 3800kb
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'