UPC- 7026: Education(贪心)

7026: Education

时间限制: 1 Sec  内存限制: 128 MB
提交: 136  解决: 53
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Seeking to cash in on the lucrative private education business, EduCorp recently established the prestigious ”Bootcamp Academy of Economics” and, counter to their early projections, is growing rapidly.
So rapidly, in fact, that the student body is already overflowing the small (but prestigious) campus building and now needs to be contained somewhere else while more new (and prestigious) buildings are built.
Each department will sell off its original space and then move into its own new rented building. As departments are deeply territorial, buildings must not be shared. Because this is an economics academy, the capacities and rents of each of all the local available buildings were easy to find by disguising the task as homework.
However, it still remains to choose which buildings to rent so as to minimise total budget. This is where you can help.

输入

•one line containing the integers n and m (1 ≤ n ≤ m ≤ 5000), the number of departments and buildings respectively.
•one line containing n integers s1 ... sn (1 ≤ si ≤ 1000 for each i), where si is the number of students in department i.
•one line containing m integers p1 ... pm (1 ≤ pi  ≤ 1000 for each i), where pi is the capacity of building i.
•one line containing m integers r1 ... rm (1 ≤ ri ≤ 1000 for each i), where ri is the yearly rental cost of building i.

 

输出

If it is not possible to rent enough buildings for all the departments, output impossible.
Otherwise, output possible.

样例输入

2 5
40 200
1000 199 201 10 50
600 300 400 200 800

样例输出

possible

来源/分类

UKIEPC2017 

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5001;
#define IO              ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define rep(i,j,k)      for(int i=j;i<k;i++)
#define per(i,j,k)      for(int i=j;i<=k;i++)
int s[maxn],cap[maxn],cost[maxn],vis[maxn];
int main(void)
{
   IO
   memset(vis,0,sizeof(vis)); 
   int n,m;   cin>>n>>m;
   rep(i,0,n) cin>>s[i];
   rep(i,0,m) cin>>cap[i];
   rep(i,0,m) cin>>cost[i];
   sort(s,s+n);
   sort(cap,cap+m);
   int count=0;
   for(int i=n-1;i>=0;i++) 
   {
   	rep(j,0,m)
   	{
       if(!vis[j]&&cap[j]>=s[i]) {
       	vis[j]=1;
       	count++;
       	break;
       }  
   	}
   }
   puts(count==n?"possible\n":"impossible\n");
} 
/**************************************************************
    Problem: 7026
    User: St064
    Language: C++
    Result: 正确
    Time:20 ms
    Memory:1776 kb
****************************************************************/

猜你喜欢

转载自blog.csdn.net/Achanss/article/details/82154088