QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#649104 | #8936. Team Arrangement | argtarg | ML | 0ms | 0kb | C++20 | 1.8kb | 2024-10-17 21:37:36 | 2024-10-17 21:37:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl '\n'
#define pii pair<int, int>
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
while (T--)solve();
return 0;
}
void solve(){
int n;
cin>>n;
vector<pii>a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i].first>>a[i].second;
}
sort(a.begin()+1,a.end());
long long ans=-1e10;
vector<int>num(n+1),w(n+1);
for(int i=1;i<=n;i++){
cin>>w[i];
}
int cnt=0,ccnt=0;
auto dfs=[&](auto dfs,int re,int x)->void{
cnt++;
if(re==0){
ccnt++;
priority_queue<int,vector<int>,greater<int>>q;
long long tmp=0;
int ok=1,l=1;
for(int i=1;i<=n;i++){
if(ok==0)break;
// cout<<num[i]<<' ';
tmp+=1ll*num[i]*w[i];
while(l<=n&&a[l].first<=i){
q.push(a[l].second);
l++;
}
for(int j=0;j<num[i]*i;j++) {
if(q.size()&&q.top()>=i){
q.pop();
}
else {
ok=0;
break;
}
}
}
// cout<<endl;
if(ok==1)ans=max(ans,tmp);
return;
}
if(x==0)return;
for(int j=x;j>=1;--j){
num[j]++;
dfs(dfs,re-j,j);
num[j]--;
}
};
dfs(dfs,n,n);
// cout<<cnt<<endl;
// cout<<ccnt<<endl;
cout<<(ans==-1e10 ? "impossible":to_string(ans))<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
3 2 3 1 2 2 2 4 5 100