大佬求调 用的是贪心的思路
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull ;
typedef long long ll;
const int N = 5000;
struct Stone{
ull pri, val, day;
double vp;
Stone(ull a, ull b, ull c, double d) : pri(a), val(b), day(c), vp(d) {}
bool operator<(const Stone& other) const {
return this->vp < other.vp;
}
// 重载大于运算符
bool operator>(const Stone& other) const {
return this->vp > other.vp;
}
};
priority_queue<Stone> sts;
ll dayUse[N];
void init(ull m){
for (int i=0;i<N;i++){
dayUse[i] = m;
}
}
int main() {
ll x;
ull n,M,m;cin>>n>>x>>M>>m;
if (m*n>=(ull)x){
cout<<0;
return 0;
}else if(M*n<(ull)x){
cout<<-1;
return 0;
}
init (M-m);
for (ull j=1;j<=n;j++){
ull num;cin>>num;
ull pris[N], vals[N];
for (ull i=0;i<num;i++)
cin>>pris[i];
for (ull i=0;i<num;i++)
cin>>vals[i];
for (ull i=0;i<num;i++)
sts.push(Stone(pris[i], vals[i], j, (double)vals[i]/(double)pris[i]));
}
x -= m*n;
ll cost = 0;
while(x && !sts.empty()){
Stone k = sts.top();sts.pop();
if (!k.vp){
cout<<-1;
return 0;
}
if(k.val > dayUse[k.day]){
k.val = dayUse[k.day];
k.vp = (long double)k.val / (long double)k.pri;
sts.push(k);
}else{
dayUse[k.day] -= k.val;
cost += k.pri;
x -= k.val;
}
}
cout<<cost;
return 0;
}