Hybrid Crystals
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 667 Accepted Submission(s): 429
>
> — Wookieepedia
Powerful, the Kyber crystals are. Even more powerful, the Kyber crystals get combined together. Powered by the Kyber crystals, the main weapon of the Death Star is, having the firepower of thousands of Star Destroyers.
Combining Kyber crystals is not an easy task. The combination should have a specific level of energy to be stablized. Your task is to develop a Droid program to combine Kyber crystals.
Each crystal has its level of energy (
* For a light-side crystal of energy level
* For a dark-side crystal of energy level
Surprisingly, there are rare neutral crystals that can be tuned to either dark or light side. Once used, it emits either
Given
Considering the NP-Hardness of this problem, the Jedi Council puts some additional constraints to the array such that the problem is greatly simplified.
First, the Council puts a special crystal of
Second, the Council has arranged the other
For those who do not have the patience to read the problem statements, the problem asks you to find whether there exists a set
where
For each test case, the first line contains two integers
The next line contains
The next line contains
2 5 9 1 1 2 3 4 N N N N N 6 -10 1 0 1 2 3 1 N L L L L D
yes no
/**
by z_guibin
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
int num[20100];
int main()
{
int t,n,k;
int a[1001];
char b[1001];
scanf("%d",&t);
while(t--)
{
getchar();
memset(num,0,sizeof(num));
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
scanf("%d %d",&n,&k);
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
//getchar();
for(int i=1; i<=n; i++)
{
cin>>b[i];
//getchar();
}
//getchar();
int down=-1,up=1;
for(int i=1;i<=n;i++)
{
if(b[i]=='N')
{
up+=a[i];
down-=a[i];
}
else if(b[i]=='L')
{
up+=a[i];
}
else if(b[i]=='D')
{
down-=a[i];
}
}
if(up>=k&&down<=k)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}