Gym 100917 J. Judgement

116 篇文章 0 订阅
96 篇文章 0 订阅
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The jury of Berland regional olympiad in informatics does not trust to contest management systems, so the Berland regional programming contest is judged by the next way. There are n judges in the jury, each judge have authority ai. When jury receives a diskette with the new solution, each jury member reads its source and votes "OK" or "WA". If after the voting ends the sum of authorities of jury members, who think that solution is correct, is equal or greater to p, then soluton is accepted, otherwise it is rejected.

Several jury members think, that current system is too complicated for them and proposed some changes: each jury member will have new authority bi, and limit is changed to q; then, in their opinion, calculations will be easier, and nothing more changes.

You are hired by the Department of Education of Berland region to check if the new system is equivalent to old one, i.e. that at any possible distribution of votes final verdict with the new and with the old parameters will be the same. If the systems differ, output an example of voting, when verdicts in both systems are different.

Input

First line of the input contains one integer n (1 ≤ n ≤ 100) — number of judges in the jury.

Second line contains n + 1 integers p, a1, a2, ..., an (1 ≤ p, ai ≤ 106) — the current acception limit and the current values of authorities of jury members, respectively.

Third line contains n + 1 integers q, b1, b2, ..., bn (1 ≤ q, bi ≤ 106) — the new acception limit and the new values of authorities of jury members, respectively.

Output

If old and new systems are equivalent, print "YES". Otherwise in the first line of output print "NO", and in second print example of voting, with different verdicts in old and new systems. Voting is encoded with the string of length n, where i-th character is '1', if i-th judge considered solution correct and '0' otherwise.

If several answers are possible, print any of them.

Examples
Input
3
8 4 5 6
2 1 1 1
Output
YES
Input
3
6 4 5 6
2 1 1 1
Output
NO
001


#include <cstdio>
#include <cstring>
#include <iostream>
#include <bitset>
#define MAXN int(1e6+10)
using namespace std;
bitset<101> ans[MAXN];
int n,p,q,a[101],b[101];
int f[MAXN];
bool deal()
{
	memset(f,-1,sizeof(f));
	for(int i=1;i <= n;i++) ans[i].reset();
	f[0]=0;
	for(int i=1;i <= n;i++)
	 for(int j=p-1-a[i];j >= 0;j--)
	  if(f[j] >= 0)
	   if(f[j+a[i]] < f[j]+b[i])
	   {
	    	f[j+a[i]]=f[j]+b[i];
	    	ans[j+a[i]]=ans[j];
	    	ans[j+a[i]].set(i);
	    	if(f[j+a[i]] >= q)
	    	{
	    		cout<<"NO"<<endl;
	    		for(int k=1;k <= n;k++) cout<<ans[j+a[i]][k];
	    		return false;
			}
	   }
	return true;  	  
}
int main()
{
	cin>>n>>p;
	for(int i=1;i <= n;i++) cin>>a[i];
	cin>>q;
	for(int i=1;i <= n;i++) cin>>b[i];
	if(!deal()) return 0;
	swap(p,q);
	for(int i=1;i <= n;i++) swap(a[i],b[i]);
	if(!deal()) return 0;
	cout<<"YES"<<endl;
 } 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值