WA on #16 求调
查看原帖
WA on #16 求调
1380676
He_XY楼主2025/8/5 11:04

Answer: 499728011202238

Output: 499723591600734

#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define mpr make_pair
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define sz(v) (int)v.size()

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;

const int inf=2e9;
const int MOD=998244353;
const int maxn=1000005;
pii v[maxn];
bool used[maxn];
int to[maxn],f[maxn];
struct Node{
	int a,b;
	bool operator < (const Node &B) const{
		return a-b<B.a-B.b;
	}
};
void solve(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>v[i].first;
	for(int i=1;i<=n;i++) cin>>v[i].second;
	sort(v+1,v+1+n,[](pii a,pii b){
		if(a.first-a.second==b.first-b.second) return a.first<b.first;
		return a.first-a.second<b.first-b.second;
	});
	for(int i=1;i<=n;i++){
		pii x=v[i];
		used[x.first]=1;
		to[x.first]=x.second;
	}
	set<Node> st;
	for(int i=1;i<=1000000;i++){
		if(used[i])	st.insert({i,to[i]});
		if(!st.empty()){
			Node x=*st.begin();
			f[i]=f[i-x.a+x.b]+1;
		}
	}
	ll ans=0;
	for(int i=1;i<=m;i++){
		int x; cin>>x;
		int l=0,r=1e9;
		int a=v[1].first,b=v[1].second;
		while(l<r){
			int mid=l+r+1>>1; 
			if(x-mid*(a-b)>=0&&x-(mid-1)*(a-b)-a>=0) l=mid;
			else r=mid-1;
		}
		ans+=l;
		x-=l*(a-b);
		ans+=f[x];
	}
	cout<<(ans*2)<<endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int32_t T=1;
	while(T--){
		solve();
	}
	return 0;
}
2025/8/5 11:04
加载中...