//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "单调队列优化多重背包": {
        "prefix": "acm-5.1CodeVS 5429",
        "body": [
            "#include<cstdio>",
            "#define Re register int",
            "const int N=7003,M=7003;",
            "int n,h,t,V,mp,tmp,v[N],w[N],c[N],Q[N],K[N],dp[M];",
            "inline void in(Re &x){",
            "\tRe fu=0;x=0;char ch=getchar();",
            "\twhile(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar();",
            "\twhile(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();",
            "\tx=fu?-x:x;",
            "}",
            "inline int max(Re a,Re b){return a>b?a:b;}",
            "inline int min(Re a,Re b){return a<b?a:b;}",
            "int main(){",
            "    in(n),in(V);",
            "    for(Re i=1;i<=n;++i)in(v[i]),in(w[i]),in(c[i]);",
            "    for(Re i=1;i<=n;++i)",
            "    \tfor(Re r=0;r<v[i];++r){",
            "    \t\th=1,t=0,mp=(V-r)/v[i];",
            "    \t\tfor(Re p=0;p<=mp;++p){",
            "    \t\t\ttmp=dp[p*v[i]+r]-w[i]*p;",
            "    \t\t\twhile(h<=t&&Q[t]<=tmp)--t;",
            "    \t\t\tQ[++t]=tmp,K[t]=p;",
            "    \t\t\twhile(h<=t&&p-K[h]>min(c[i],V/v[i]))++h;",
            "    \t\t\tdp[p*v[i]+r]=max(dp[p*v[i]+r],Q[h]+p*w[i]);",
            "\t\t\t}",
            "\t\t}",
            "    printf(\"%d\",dp[V]);",
            "}",
            ""
        ],
        "description": "插入 单调队列优化多重背包"
    }
}