cf C - Booking System

C - Booking System
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Innovation 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 opening moment 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.

Input

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of requests from visitors. Then n lines follow. 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-separated integers:r1, r2, ..., rk(1 ≤ ri ≤ 1000) — the maximum number of people that can sit at each table.

Output

In 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 requests and 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 Input

Input
3
10 50
2 100
5 30
3
4 6 9
Output
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;///用过就赋值为-1
                    temp=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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
xjc-cf3600-c压力显示表是一种专门用于测量和显示系统内部压力的设备。该表具有以下特点和功能。 首先,xjc-cf3600-c压力显示表具有高精度和稳定性。它采用先进的传感技术和精密的测量装置,能够准确地测量系统内部的压力值,并且在长时间使用过程中保持稳定的工作状态。这使得该表能够提供可靠的压力数据,为系统运行提供准确的参考。 其次,xjc-cf3600-c压力显示表具有直观的显示界面。它采用大屏幕液晶显示屏,能够清晰地显示出当前的压力数值。同时,该表还提供灯光背光功能,使得在暗处或夜间也能清晰地读取显示结果。这样,操作人员可以方便地观察和记录压力情况。 此外,xjc-cf3600-c压力显示表还具有多种报警功能。它能够根据预设的上下限值,自动发出声音或灯光报警信号,提醒操作人员系统内部压力超过规定范围,以便及时采取措施。这种报警功能有效地保护系统的安全运行,防止因过高或过低的压力而导致的损坏或事故发生。 最后,xjc-cf3600-c压力显示表具有良好的耐用性和可靠性。它采用高品质的材料和工艺制作而成,具有较强的抗震、耐腐蚀和抗干扰能力。此外,该表还具有防水、防尘和防爆等特性,能够适应各种恶劣的工作环境。 总之,xjc-cf3600-c压力显示表是一种功能强大的压力测量和显示设备,具有高精度、直观的显示界面、多种报警功能以及良好的耐用性和可靠性。它可以广泛应用于各种工业领域,为系统运行提供准确的压力监测和控制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值