Codeforces Round #222 (Div. 1) B. Preparing for the Contest 二分+线段树

时间:2023-01-16 11:33:10

B. Preparing for the Contest

题目连接:

http://codeforces.com/contest/377/problem/B

Description

Soon there will be held the world's largest programming contest, but the testing system still has m bugs. The contest organizer, a well-known university, has no choice but to attract university students to fix all the bugs. The university has n students able to perform such work. The students realize that they are the only hope of the organizers, so they don't want to work for free: the i-th student wants to get ci 'passes' in his subjects (regardless of the volume of his work).

Bugs, like students, are not the same: every bug is characterized by complexity aj, and every student has the level of his abilities bi. Student i can fix a bug j only if the level of his abilities is not less than the complexity of the bug: bi ≥ aj, and he does it in one day. Otherwise, the bug will have to be fixed by another student. Of course, no student can work on a few bugs in one day. All bugs are not dependent on each other, so they can be corrected in any order, and different students can work simultaneously.

The university wants to fix all the bugs as quickly as possible, but giving the students the total of not more than s passes. Determine which students to use for that and come up with the schedule of work saying which student should fix which bug.

Input

The first line contains three space-separated integers: n, m and s (1 ≤ n, m ≤ 105, 0 ≤ s ≤ 109) — the number of students, the number of bugs in the system and the maximum number of passes the university is ready to give the students.

The next line contains m space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — the bugs' complexities.

The next line contains n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109) — the levels of the students' abilities.

The next line contains n space-separated integers c1, c2, ..., cn (0 ≤ ci ≤ 109) — the numbers of the passes the students want to get for their help.

Output

If the university can't correct all bugs print "NO".

Otherwise, on the first line print "YES", and on the next line print m space-separated integers: the i-th of these numbers should equal the number of the student who corrects the i-th bug in the optimal answer. The bugs should be corrected as quickly as possible (you must spend the minimum number of days), and the total given passes mustn't exceed s. If there are multiple optimal answers, you can output any of them.

Sample Input

3 4 9

1 3 1 2

2 1 3

4 3 6

Sample Output

YES

2 3 2 3

Hint

题意

有一个学校,有m个bug,有n个大学生,每个大学生的能力值是b[i],bug的能力值是a[i],如果b[i]>=a[j],那么第i个人能够修复j bug

现在每个大学生你需要支付c[i]元,支付给他之后,他可以每天修复一个能力值小于等于他能力值的bug

你需要尽量少的天数,以及在花费小于s的情况下,修复这些bug

问你怎么去做?

题解:

如果能在T天修复完,那么显然也能够在T+1天内修复完,所以这个是具备二分性的

然后我们就二分答案,那么我们找到一个最便宜的人去修复[m,m-T+1]的bug,再找一个人去修复[m-T,m-2T+1],等等等

这样就好了

然后我们用一个线段树去维护这个玩意儿就好了

代码

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 15;

struct Person{
int cost , val , idx ;
friend bool operator < (const Person & a , const Person & b){
return a.val < b.val;
}
}p[maxn];
int N , M , S , maxv , ans[maxn]; pair < int , int > a[maxn]; bool cmp( const pair < int , int > & x , const pair < int , int > & y){
return x.first > y.first;
} struct Sgtree{ struct node{
int l , r ;
int pos , minv;
}tree[maxn << 2]; void Maintain( int o ){
int lson = o << 1 , rson = o << 1 | 1;
if( tree[lson].minv < tree[rson].minv ) tree[o].minv = tree[lson].minv , tree[o].pos = tree[lson].pos;
else tree[o].minv = tree[rson].minv , tree[o].pos = tree[rson].pos;
} void Build( int l , int r , int o ){
tree[o].l = l , tree[o].r = r ;
if( r > l ){
int mid = l + r >> 1;
Build( l , mid , o << 1 );
Build( mid + 1 , r , o << 1 | 1 );
Maintain( o );
}else tree[o].pos = l , tree[o].minv = p[l].cost;
} void Modify( int p , int o ){
int l = tree[o].l , r = tree[o].r;
if( l == r ) tree[o].minv = 2e9;
else{
int mid = l + r >> 1;
if( p <= mid ) Modify( p , o << 1 );
else Modify( p , o << 1 | 1 );
Maintain( o );
}
} pair < int , int > ask( int ql , int o ){
int l = tree[o].l , r = tree[o].r;
if(ql <= l) return make_pair( tree[o].minv , tree[o].pos );
else{
int mid = l + r >> 1;
pair < int , int > ls , rs ;
ls.first = rs.first = 2e9;
if( ql <= mid ) ls = ask( ql , o << 1 );
rs = ask( ql , o << 1 | 1 );
if( ls.first < rs.first ) return ls;
return rs;
}
} }Sgtree; bool solve( int T ){
Sgtree.Build(1 , N , 1);
vector < int > vi;
int j = N , money = S;
for(int i = 1 ; i <= M ; i += T){
while( j >= 1 && p[j].val >= a[i].first ) -- j;
pair < int , int > rp = Sgtree.ask( j + 1 , 1 );
if( rp.first > money ) return false;
money -= rp.first;
Sgtree.Modify(rp.second , 1);
vi.push_back( p[rp.second].idx );
}
int lst = 0 , ptr = 0;
for(int i = 1 ; i <= M ; ++ i){
ans[a[i].second] = vi[ptr];
++ lst;
if( lst == T ) lst = 0 , ++ ptr;
}
return true;
} int main( int argc , char * argv[] ){
scanf("%d%d%d",&N,&M,&S);
for(int i = 1 ; i <= M ; ++ i){
scanf("%d" , &a[i].first);
a[i].second = i;
maxv = max( maxv , a[i].first );
}
int find = 0;
for(int i = 1 ; i <= N ; ++ i) scanf("%d" , &p[i].val);
for(int i = 1 ; i <= N ; ++ i){
scanf("%d" , &p[i].cost);
p[i].idx = i ;
if( p[i].val >= maxv && p[i].cost <= S ) find = 1;
}
if( find == 0 ) printf("NO\n");
else{
sort( a + 1 , a + M + 1 , cmp );
sort( p + 1 , p + N + 1 );
int l = 1 , r = max(N,M);
while( l < r ){
int mid = l + r >> 1;
if( solve( mid ) ) r = mid;
else l = mid + 1;
}
solve( l );
printf("YES\n");
for(int i = 1 ; i <= M ; ++ i) printf("%d ", ans[i]);
printf("\n");
}
return 0;
}

Codeforces Round #222 (Div. 1) B. Preparing for the Contest 二分+线段树的更多相关文章

  1. Codeforces Round &num;365 &lpar;Div&period; 2&rpar; D&period; Mishka and Interesting sum 离线&plus;线段树

    题目链接: http://codeforces.com/contest/703/problem/D D. Mishka and Interesting sum time limit per test ...

  2. Codeforces Round &num;538 &lpar;Div&period; 2&rpar; F 欧拉函数 &plus; 区间修改线段树

    https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...

  3. Codeforces Round &num;345 &lpar;Div&period; 1&rpar; D&period; Zip-line 上升子序列 离线 离散化 线段树

    D. Zip-line 题目连接: http://www.codeforces.com/contest/650/problem/D Description Vasya has decided to b ...

  4. Codeforces Round &num;370 &lpar;Div&period; 2&rpar; E&period; Memory and Casinos &lpar;数学&amp&semi;&amp&semi;概率&amp&semi;&amp&semi;线段树&rpar;

    题目链接: http://codeforces.com/contest/712/problem/E 题目大意: 一条直线上有n格,在第i格有pi的可能性向右走一格,1-pi的可能性向左走一格,有2中操 ...

  5. Codeforces Round &num;FF &lpar;Div&period; 2&rpar;&lowbar;&lowbar;E&period; DZY Loves Fibonacci Numbers &lpar;CF447&rpar; 线段树

    http://codeforces.com/contest/447/problem/E 题意: 给定一个数组, m次操作, 1 l r 表示区间修改, 每次 a[i] +  Fibonacci[i-l ...

  6. Codeforces Round &num;250 &lpar;Div&period; 1&rpar; D&period; The Child and Sequence(线段树)

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  7. DFS Codeforces Round &num;306 &lpar;Div&period; 2&rpar; B&period; Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  8. Codeforces Round &num;367 &lpar;Div&period; 2&rpar; D&period; Vasiliy&&num;39&semi;s Multiset (0&sol;1-Trie树)

    Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out ...

  9. Codeforces Round &num;222 &lpar;Div&period; 1&rpar; &lpar;ABCDE&rpar;

    377A Maze 大意: 给定棋盘, 保证初始所有白格连通, 求将$k$个白格变为黑格, 使得白格仍然连通. $dfs$回溯时删除即可. #include <iostream> #inc ...

随机推荐

  1. hdu 5424 Rikka with Graph II &lpar;BestCoder Round &num;53 &lpar;div&period;2&rpar;&rpar;&lpar;哈密顿通路判断)

    http://acm.hdu.edu.cn/showproblem.php?pid=5424 哈密顿通路:联通的图,访问每个顶点的路径且只访问一次 n个点n条边 n个顶点有n - 1条边,最后一条边的 ...

  2. FragmentTransaction&period;addToBackStack无效的问题

    FragmentTransaction.addToBackStack无效的问题: 如果当前的类继承的ActionBarActivity,则FragmentManager必须来自v4包,这样addToB ...

  3. PCL学习笔记(一)

    由于项目需要,开始学习一下HP公司的PCL打印语言,发现这方面的中文资料非常少,我做下记录也为后人提供便利. 关于PCL的介绍可以参考wiki百科 http://zh.wikipedia.org/zh ...

  4. 慎得慌二u赫然共和任务i个屁

    http://www.huihui.cn/share/8424421 http://www.huihui.cn/share/8424375 http://www.huihui.cn/share/842 ...

  5. Ubuntu下安装MySQL 5&period;6&period;23

    Ubuntu下安装MySQL 5.6.23 1.下载相应Linux-generic的源代码包.解压,将解压后的文件夹重命名为mysql.移动到/usr/local文件夹下: tar –xzf mysq ...

  6. ASP&period;Net MVC请求处理流程

    ASP.Net MVC请求处理流程 好听的歌 我一直觉得看一篇文章再听一首好听的歌,真是种享受.于是,我在这里嵌入一首好听的歌,当然你觉得不想听的话可以点击停止,歌曲 from 王菲 <梦中人& ...

  7. vue2&period;0实现分页组件

    最近使用vue2.0重构项目, 需要实现一个分页的表格, 没有找到合适的组件, 就自己写了一个, 效果如下: 该项目是使用 vue-cli搭建的, 如果你的项目中没有使用webpack,请根据代码自己 ...

  8. Unity3D里怎样隐藏物体

    方法很多: 1.改position,移到视野外,推荐,最节省 2.gameObject.SetActive (false); //要提前引用,要不你就改不回来了... 3.renderer.enabl ...

  9. idea使用maven打包项目

    第一步:打开maven Projects 第二步.找到package 第三步,运行.到路径下面去找打包的文件吧. 第二种方法: 使用命令 cmd进入项目目录,例如项目在D盘项目名poject 输入: ...

  10. 2015 HIAST Collegiate Programming Contest D

    You have been out of Syria for a long time, and you recently decided to come back. You remember that ...