B. Lunar New Year and Food Ordering
Posted lishengkangshidatiancai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了B. Lunar New Year and Food Ordering相关的知识,希望对你有一定的参考价值。
#include<bits/stdc++.h>//标记数组法,在结构体外面开一个数组来标记这个元素是否被取完,对结构体排序,遍历结构体时如果标记数组为0跳过就好 using namespace std; typedef long long ll; struct student{ int index; int c; int r; }stu[100010]; int num[100010]; int cost[100010]; bool cmp(student A,student B) { if(A.c==B.c) return A.index<B.index; return A.c<B.c; } int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { int a; scanf("%d",&a); stu[i].r=a; stu[i].index=i; num[i]=a; } for(int i=1;i<=n;i++) { int c; scanf("%d",&c); stu[i].c=c; cost[i]=c; } sort(stu+1,stu+1+n,cmp); int pos=1; for(int i=1;i<=m;i++) { int t,d; scanf("%d%d",&t,&d); if(pos==n+1) { printf("0 "); continue; } ll res=0; if(num[t]) { if(num[t]>=d) { num[t]-=d; printf("%lld ",1LL*d*cost[t]); continue; } else { d-=num[t]; res+=(1LL*num[t]*cost[t]); num[t]=0; } } while(pos<=n) { while(pos<=n&&num[stu[pos].index]==0) { pos++; } if(pos==n+1) break; if(num[stu[pos].index]>d) { num[stu[pos].index]-=d; res+=(1LL*d*cost[stu[pos].index]); d=0; } else { d-=num[stu[pos].index]; res+=(1LL*num[stu[pos].index]*cost[stu[pos].index]); num[stu[pos].index]=0; pos++; } if(d==0) break; } if(pos==n+1&&d>0) printf("0 "); else printf("%lld ",res); } }
以上是关于B. Lunar New Year and Food Ordering的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #536 (Div. 2) - D. Lunar New Year and a Wander(最短路)
CF1106F Lunar New Year and a Recursive Sequence
CF - 1106 E Lunar New Year and Red Envelopes DP
Codeforces 1106C Lunar New Year and Number DivisionLunar |数学