cf C - Booking System
2015-12-04 21:22
393 查看
C - Booking SystemTime Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d& %I64uSubmit Status Practice CodeForces416CDescriptionInnovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.There are n booking requests received by now. Each request is characterized by two numbers: ci and pi —the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the openingmoment at 18:00 to the closing moment.Unfortunately, there only are k tables in the restaurant. For each table, we know ri —the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.InputThe first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of requests from visitors. Then n linesfollow. Each line contains two integers: ci, pi(1 ≤ ci, pi ≤ 1000)— the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly.The next line contains integer k (1 ≤ k ≤ 1000) — the number of tables in the restaurant. The last line contains k space-separatedintegers:r1, r2, ..., rk(1 ≤ ri ≤ 1000) —the maximum number of people that can sit at each table.OutputIn the first line print two integers: m, s — the number of accepted requests and the total money you get from these requests, correspondingly.Then print m lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requestsand the tables are consecutively numbered starting from 1 in the order in which they are given in the input.If there are multiple optimal answers, print any of them.Sample InputInput
3 10 50 2 100 5 30 3 4 6 9Output
2 130 2 1 3 2
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>using namespace std;const int MAXN=1005;struct ac{int pi,ci,ii;} d[MAXN];struct ac2{int ii,vi;} ko[MAXN];int cmp(ac a,ac b){if(a.pi!=b.pi)return a.pi>b.pi;return a.ci<b.ci;}int cmp2(ac2 a,ac2 b){return a.vi<b.vi;}int n,k;int main(){while(scanf("%d",&n)!=-1){for(int i=0; i<n; i++){//cin>>d[i].ci>>d[i].pi;scanf("%d%d",&d[i].ci,&d[i].pi);d[i].ii=i+1;}sort(d,d+n,cmp);//cin>>k;scanf("%d",&k);for(int i=0; i<k; i++){//cin>>ko[i].vi;scanf("%d",&ko[i].vi);ko[i].ii=i+1;}sort(ko,ko+k,cmp2);/*for(int i=0;i<k;i++){cout<<ko[i].vi<<" "<<ko[i].ii<<endl;}*/int ans=0,o=0;ac2 cp[1005];///结构体 ,记录桌子标号 ,旅游团下标for(int i=0; i<n; i++){int p=d[i].ci;int temp=0;for(int j=0; j<k; j++){if(ko[j].vi>=p){ko[j].vi=-1;///用过就赋值为-1temp=ko[j].ii;///桌子下标break;}}if(temp){cp[o].ii=d[i].ii;///旅游团下标cp[o++].vi=temp;///桌子下标ans+=d[i].pi;}}printf("%d %d\n",o,ans);for(int i=0; i<o; i++){printf("%d %d\n",cp[i].ii,cp[i].vi);}// cout<<cp[i].f<<" "<<cp[i].t<<endl;}return 0;}
相关文章推荐
- centos下httpd-2.4的编译安装
- leetcode Count and Say
- project euler 40
- centos下httpd-2.4的编译安装
- android 布局优化(一)
- 问题处理:找不到Pch预编译文件?
- MATLAB 利用filter函数实现滑动平均滤波
- 什么是Code First(EF Code First 系列)
- Android 图片选择器
- cfB - Art Union
- HTML 元素和属性--备份
- linux 磁盘性能fio-hdd
- project euler 39
- if语句实现分支结构 课后习题
- Reverse Bits
- 关于×××重复定义在limcmt.lib中的问题。
- 终端卸载Ubuntu软件
- 2-Fourth Scrum Meeting20151204
- 折腾了一个晚上,终于发表了第一篇学习技术博客,
- HDU 1086 You can Solve a Geometry Problem too