2014年第一发。。。。
二分查找最短时间+贪心找可以满足条件的要加最便宜的人
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=100100;
typedef pair<int,int> pII;
typedef pair<pair<int,int>,int> pIIi;
int n,m,p,arr[maxn];
pII a[maxn];
pIIi s[maxn];
bool ck(int x)
{
priority_queue<int> q;
int i=n-1,j=m-1,cost=0;
while(j>=0)
{
int g=a[j].first;
while(i>=0&&s[i].first.first>=g)
{
q.push(-s[i].first.second);
i--;
}
if(q.empty()) return false;
cost-=q.top();q.pop();
if(cost>p) return false;
j-=x;
}
return true;
}
void print(int x)
{
puts("YES");
priority_queue<pII> q;
int i=n-1,j=m-1,cost=0;
while(j>=0)
{
int g=a[j].first;
while(i>=0&&s[i].first.first>=g)
{
q.push(make_pair(-s[i].first.second,s[i].second));
i--;
}
pII XII=q.top(); q.pop();
for(int k=0;k<x&&j>=0;k++,j--)
{
arr[a[j].second]=XII.second;
}
}
for(int i=0;i<m;i++)
{
printf("%d ",arr[i]);
}
putchar(10);
}
int main()
{
scanf("%d%d%d",&n,&m,&p);
for(int i=0;i<m;i++)
{
scanf("%d",&a[i].first);
a[i].second=i;
}
for(int i=0;i<n;i++)
{
scanf("%d",&s[i].first.first);
s[i].second=i+1;
}
for(int i=0;i<n;i++)
{
scanf("%d",&s[i].first.second);
}
sort(a,a+m); sort(s,s+n);
int low=0,high=m,mid,day;
while(low<=high)
{
mid=(low+high)>>1;
if(ck(mid)) day=mid,high=mid-1;
else low=mid+1;
}
if(!ck(day))
{
puts("NO");
}
else
{
print(day);
}
return 0;
}