求佬们给组hack
查看原帖
求佬们给组hack
877860
Just_Love_You楼主2024/3/22 11:40
#include<bits/stdc++.h>
#define endl '\n'
#define int signed long long
#define double long double
using namespace std;
constexpr int N=2e7+10;
constexpr int M=3e3+10;
constexpr int mod=998244353;
void solve()
{
    int n;
    cin >> n;
    vector<pair<int,int>> num(n);
    priority_queue<pair<int,int>> pq;
    for(int i=0;i<n;i++)
    {
        cin >> num[i].first;
    }
    for(int i=0;i<n;i++)
    {
        cin >> num[i].second;
        pq.push({num[i].first,num[i].second});
    }
    int ans=0;
    int cnt=0;
    int tmp=0;
    priority_queue<int,vector<int>,greater<>> qu;
    for(int i=1;i<=n;i++)
    {
        while(!qu.empty()&&qu.top()<i)
        {
            qu.pop();
        }
        while(!pq.empty()&&qu.size()<i)
        {
            if(pq.top().second>=i)
            {
                tmp=pq.top().first;
                qu.push(pq.top().second);
            }
            pq.pop();
        }
        if(qu.size()==i)
        {
            if(ans<i*tmp)
            {
                ans=i*tmp;
                cnt=i;
            }
        }else break;
    }
    cout << ans << " " << cnt << endl;
}
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int o;
    cin >> o;
    while(o--)
    solve();

    return 0;
}
//
//⠀⠀⠀             ⠀⢸⣿⣿⣿⠀⣼⣿⣿⣦⡀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀ ⠀⢸⣿⣿⡟⢰⣿⣿⣿⠟⠁
//⠀⠀⠀⠀⠀⠀⠀⢰⣿⠿⢿⣦⣀⠀⠘⠛⠛⠃⠸⠿⠟⣫⣴⣶⣾⡆
//⠀⠀⠀⠀⠀⠀⠀⠸⣿⡀⠀⠉⢿⣦⡀⠀⠀⠀⠀⠀⠀ ⠛⠿⠿⣿⠃
//⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣦⠀⠀⠹⣿⣶⡾⠛⠛⢷⣦⣄⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⠀⠀⠈⠉⣀⡀⠀ ⠀⠙⢿⡇
//⠀⠀⠀⠀⠀⠀⢀⣠⣴⡿⠟⠋⠀⠀⢠⣾⠟⠃⠀⠀⠀⢸⣿⡆
//⠀⠀⠀⢀⣠⣶⡿⠛⠉⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⢸⣿⠇
//⢀⣠⣾⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⢀⣼⣧⣀⠀⠀⠀⢀⣼⠇
//⠈⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⡿⠋⠙⠛⠛⠛⠛⠛⠁
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣾⡿⠋⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⢾⠿⠋⠀
//
2024/3/22 11:40
加载中...