#include <bits/stdc++.h>
using namespace std;
long long a[100001],b[100001];
int hv[100001];
int danhdau[100];
int n,m;
int kq=0;
void kt()
{
long long tong=0;
int i2=1;
for (int i=1;i<=m;i++)
{
tong=tong+b[hv[i]];
if (i2==n+1)
{
kq=1;
return;
}
if (tong>a[i2])
{
// cout << "kk" << '\n';
return;
}
if (tong==a[i2])
{
tong=0;
i2++;
}
// cout << b[hv[i]] << " ";
}
// cout << '\n';
if (i2==n+1) kq=1;
return;
}
void kk (int i)
{
if (i==m+1)
{
kt();
return;
}
// int mid=(l+r)>>1;
for (int i2=1;i2<=m;i2++)
{
if (!danhdau[i2])
{
hv[i]=i2;
danhdau[i2]=1;
kk(i+1);
danhdau[i2]=0;
}
}
}
signed main ()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i=1;i<=n;i++)
{
cin >> a[i];
}
for (int i=1;i<=m;i++) cin >> b[i];
kk(1);
if (kq) cout << "YES" << '\n';
else cout << "NO" << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
182 ms |
336 KB |
Output is correct |
4 |
Execution timed out |
1085 ms |
212 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
320 KB |
Output is correct |
2 |
Correct |
171 ms |
320 KB |
Output is correct |
3 |
Correct |
213 ms |
320 KB |
Output is correct |
4 |
Correct |
152 ms |
320 KB |
Output is correct |
5 |
Correct |
152 ms |
320 KB |
Output is correct |
6 |
Correct |
163 ms |
320 KB |
Output is correct |
7 |
Correct |
180 ms |
320 KB |
Output is correct |
8 |
Correct |
169 ms |
336 KB |
Output is correct |
9 |
Correct |
165 ms |
340 KB |
Output is correct |
10 |
Correct |
152 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1076 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
182 ms |
336 KB |
Output is correct |
4 |
Execution timed out |
1085 ms |
212 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |