QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#540620#8936. Team Arrangementucup-team3699#WA 0ms3744kbC++201.1kb2024-08-31 17:30:332024-08-31 17:30:33

Judging History

This is the latest submission verdict.

  • [2024-08-31 17:30:33]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3744kb
  • [2024-08-31 17:30:33]
  • Submitted

answer

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define F first 
#define S second 

const int mol=998244353;

vector<pair<int, int>>a;
priority_queue<int, vector<int>, greater<>>ha;
vector<int>rr[65];
int ans=-1e18, tot=0, n, w[65];
void dfs(int sum, int t){
    if(sum==n){
        ans=max(ans, tot);
        return;
    }
    auto pre=ha;
    for(int i=t;i<=n-sum;i++){
        if(i!=n-sum&&n-sum-i<i) continue;
        for(int j=t+1;j<=i;j++){
            for(int ii: rr[j]) ha.push(ii);
        }
        if(ha.size()==0||ha.top()<i) continue;
        ha.pop();
        tot+=w[i];
        dfs(sum+i, i);
        ha=pre;
        tot-=w[i];
    }
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int l, r;
        cin>>l>>r;
        rr[l].pb(r);
    }    
    for(int i=1;i<=n;i++) cin>>w[i];
    dfs(0, 0);
    if(ans==-1e18){
        cout<<"impossible\n";
        return;
    }
    cout<<ans<<"\n";
}


signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

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

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:

7

result:

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