比赛 26暑假集训模拟赛1 评测结果 AWWTTTTTTTTTTTTTTTTTT
题目名称 Haybale Stacks 最终得分 4
用户昵称 杨蕙宇 运行时间 56.402 s
代码语言 C++ 内存使用 3.98 MiB
提交时间 2026-06-29 11:03:56
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int N=5e5+10;
const int M=2510;
ll t,n,a[N],m;
struct node{
    ll p,s,c;
}w[M];
bool cmp(node x,node y){
    return x.c*y.s<y.c*x.s;
}
int solve(ll x){
    ll sum=0;
    for(int i=1;i<=m;i++){
        if(w[i].p>x){
            continue;
        }
        while(x>=w[i].p){
            sum+=w[i].c;
            if(x-w[i].s>=w[i].p){
                x-=w[i].s;
            }
            else{
                x=w[i].p-1;
            }
        }
    }
    if(x==0)return sum;
}
int main(){
    freopen("Stacks.in","r",stdin);
    freopen("Stacks.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        cin>>m;
        for(int i=1;i<=m;i++)cin>>w[i].p>>w[i].s>>w[i].c;
        sort(w+1,w+1+m,cmp);
        for(int i=1;i<=n;i++){
            cout<<solve(a[i])<<" ";
        }
        cout<<"\n";
    }
    return 0;
}
/*
1
1
10
4
101 1 1
1 4 8
9 3 5
15 2 3
*/