90分,TLE,求助!!!
查看原帖
90分,TLE,求助!!!
770891
NTT__int128楼主2023/8/28 23:05
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#define int unsigned long long
using namespace std;
int n , s , l , h[200005] , a , cnt , z , y ;
struct node
{
	int h , a ;
	bool operator < (const node &x) const{
		return h < x.h ;
	}
} ;
priority_queue < node > q , w ;
priority_queue < long long > p ;
bool check(int x)
{
	w = q ;
    while(!w.empty())
    {
    	p.push(w.top().h + w.top().a * x) ;
    	w.pop() ;
    }
    int sum = 0 ;
    while(!p.empty() && p.top() >= l)
    {
        sum += p.top() ;
        p.pop() ;
    }
    if(sum >= s)    return 1 ;
    return 0 ;
}
signed main(){
	ios::sync_with_stdio(0) ;
	cin.tie(0) ;
	cout.tie(0) ;
	cin >> n >> s >> l ;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> h[i] ;
	}
	for(int i = 1 ; i <= n ; i++)
	{
	    cin >> a ;
	    q.push({h[i] , a}) ;
	    y = ceil((max(s , l) - h[i]) * 1.0 / a) ;
	}
	while(z < y)
	{
		int mid = (z + y) / 2 ;
		if(check(mid))	y = mid ;
		else	z = mid + 1 ;
	}
	cout << y ;
	return 0 ;
}
2023/8/28 23:05
加载中...