codeforces Round #241(div2) C解题报告

C. Booking System
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
input
3
10 50
2 100
5 30
3
4 6 9
output
2 130
2 1
3 2

题目大意:

        一家酒店,接到n个订单,然而位置有限,只有k个桌子.

        n个订单包含2个信息:c和p, c表示来多少人, p表示盈利多少.

        k个桌子包含一个信息: r, r表示一个桌子容纳多少人.

        每条订单的人群只愿接受一个桌子,即不愿意分开做,也不愿意跟其他人做一起.(也就是说,一个桌子独占着),否则他们将不会来,而且也不会产生任何盈利.

        需要从中拒绝掉一些订单(如果够就不需要拒绝了),让盈利最大.


解法:

        由于不能拼桌,那么只能筛选出利益最大,而且有桌子可以接待的订单.可以贪心,并且尽可能让桌子的容量跟该订单的容量恰到好处(如若过大,会影响到其他订单,因为人数和盈利不成正比).

        将桌子的容量排序,从最小的桌子开始,挑选出该桌子容量可以承受而且利益最大的订单,并记录下来.


代码:

#include <cstdio>
#include <algorithm>

using namespace std;

struct typ1{
	int s, p;
}vis[1010];

struct typ2{
	int n, i;
}tab[1010];

int n, k, ans, m;
int use[1010];
bool flag[1010];

bool cmp(typ2 a, typ2 b) {
	if (a.n < b.n)  return(true);
	return(false);
}

void init() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)  scanf("%d%d", &vis[i].s, &vis[i].p);

	scanf("%d", &k);
	for (int i = 1; i <= k; i++) {
		scanf("%d", &tab[i].n);
		tab[i].i = i;
	}
}

void solve() {
	sort(tab+1, tab+1+k, cmp);  //将桌子容量排序

	for (int i = 1; i <= k; i++) {  //从最小的桌子开始
		for (int j = 1; j <= n; j++)  //搜寻出满足该桌子容量,且利益最大的订单
			if (tab[i].n >= vis[j].s && vis[use[i]].p < vis[j].p && !flag[j])
				use[i] = j;  //标记该订单已经被接纳

		flag[use[i]] = true;
	}

	for (int i = 1; i <= k; i++) {
		if (use[i] != 0) {
			ans += vis[use[i]].p;
			m++;
		}
	}

	printf("%d %d\n", m, ans);
	for (int i = 1; i <= k; i++)
		if (use[i] != 0)
			printf("%d %d\n", use[i], tab[i].i);
}

int main() {
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);

	init();
	solve();
}


        


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值