QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#541980#8936. Team Arrangementucup-team3474#WA 0ms3616kbC++231.8kb2024-08-31 21:52:002024-08-31 21:52:00

Judging History

This is the latest submission verdict.

  • [2024-08-31 21:52:00]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3616kb
  • [2024-08-31 21:52:00]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std ;
void solve()
{
    int n ;
    cin >> n ;
    vector<pair<int , int>> a(n) ;
    for(int i = 0 ; i < n ; i ++)  cin >> a[i].first >> a[i].second ;
    sort(a.begin() , a.end() , [&](pair<int , int> x , pair<int , int> y)
    {
        if(x.second != y.second)  return x.second > y.second ;
        else  return x.first > y.first ;
    }) ;
    vector<int> w(n + 1) ;
    for(int i = 1 ; i <= n ; i ++)  cin >> w[i] ;
    multiset<int> s ;
    int ans = -1e9 ;
    int sum = 0 ;
    int cur = 0 ;
    function<void(int , int)> dfs = [&](int lst , int rev)
    {
        if(rev == 0)
        {
            if(cur == n and s.empty())  ans = max(ans , sum) ;
            return ;
        }
        int up = rev ;
        if(!s.empty())  up = min(up , *s.begin()) ;
        for(int i = lst ; i >= 1 ; i --)
        {
            sum += w[i] ;
            int cur2 = cur ;
            while(cur < n and a[cur].first <= i)  s.insert(a[cur].second) , cur += 1 ;
            if(s.size() >= i and (*s.begin() >= i))
            {
                vector<int> z ;
                for(int _ = 1 ; _ <= i ; _ += 1)
                {
                    int x = *s.begin() ;
                    z.push_back(x) ;
                    s.erase(s.begin()) ;
                }
                dfs(i , rev - i) ;
                for(auto x : z)  s.insert(x) ;
            }
            sum -= w[i] ;
            while(cur > cur2)  s.erase(s.find(a[cur - 1].second)) , cur -= 1 ;
        }
    } ;
    dfs(n , n) ;
    if(ans < -9e8)  cout << "impossible\n" ;
    else  cout << ans << '\n' ;
}
int main()
{
    std::ios::sync_with_stdio(false) , cin.tie(0) ;

    int T = 1 ;
    while (T --)  solve() ;

    return 0 ;
}

詳細信息

Test #1:

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

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

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

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

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:

impossible

result:

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