CodeForces #317 (div2) B.Order Book

来源:互联网 发布:注册单和淘宝单的区别 编辑:程序博客网 时间:2024/04/29 05:03

题目大意:

这道题看懂题目就应该会做了……给出两种操作,操作对象相同的操作值进行合并,两种操作,都降序输出,如果操作数小于某个值,则尽可能的输出。


解题思路:

模拟就好了吧……


#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<iostream>#include<algorithm>#include<set>#define LL long long#define db double#define maxn 10000000#define EPS 1e-15#define max(a,b) ((a>b)?(a):(b))#define min(a,b) ((a<b)?(a):(b))using namespace std;int n,m;int buy[100100];int sell[100100];int main(){    while(scanf("%d%d",&n,&m)!=EOF){        memset(buy,0,sizeof(buy));        memset(sell,0,sizeof(sell));        char str[11];        int x,y;        for(int i=0;i<n;i++){           scanf("%s%d%d",str,&x,&y);           if(strcmp(str,"B") == 0){               buy[x] += y;           }else{                sell[x] += y;           }        }        int t = 0;        int p = 0;        for(int i=0;i<=100000;i++)        {            if(t<m && sell[i]){                t++;                p = i;            }else if(t>=m){                break;            }        }        for(int i=p;i>=0;i--){            if(sell[i]){                printf("S %d %d\n",i,sell[i]);                t++;            }        }        t = 0;        for(int i=100000;i>=0;i--){            if(t<m && buy[i]){                printf("B %d %d\n",i,buy[i]);                t++;            }else if(t>=m){                break;            }        }    }    return 0;}



0 0