#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)
int main() {
ll N,K;
cin >> N >> K;
N*=2;
vector<ll> l(N),r(N),s(N);
rep(i,N){
cin >> l[i] >> r[i] >> s[i];
l[i]--,r[i]--;
}
bool ans=false;
rep(bit,1<<N){
vector<ll> L(N/2,-1),R(N/2,-1);
rep(i,N){
if(bit&(1<<i)) L[l[i]]=i;
else R[r[i]]=i;
}
ll cnt_l=0,cnt_r=0;
rep(i,N/2){
if(L[i]==-1){
cnt_l=-1;
break;
}
cnt_l+=s[L[i]];
}
rep(i,N/2){
if(R[i]==-1){
cnt_r=-1;
break;
}
cnt_r+=s[R[i]];
}
if(cnt_l==-1||cnt_r==-1) continue;
if(abs(cnt_l-cnt_r)<=K) ans=true;
}
if(ans) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
344 KB |
Output is correct |
2 |
Correct |
113 ms |
412 KB |
Output is correct |
3 |
Correct |
108 ms |
344 KB |
Output is correct |
4 |
Correct |
115 ms |
416 KB |
Output is correct |
5 |
Correct |
113 ms |
408 KB |
Output is correct |
6 |
Correct |
110 ms |
600 KB |
Output is correct |
7 |
Correct |
115 ms |
416 KB |
Output is correct |
8 |
Correct |
112 ms |
412 KB |
Output is correct |
9 |
Correct |
112 ms |
348 KB |
Output is correct |
10 |
Correct |
111 ms |
344 KB |
Output is correct |
11 |
Correct |
113 ms |
348 KB |
Output is correct |
12 |
Correct |
114 ms |
344 KB |
Output is correct |
13 |
Correct |
112 ms |
348 KB |
Output is correct |
14 |
Correct |
111 ms |
412 KB |
Output is correct |
15 |
Correct |
110 ms |
416 KB |
Output is correct |
16 |
Correct |
113 ms |
412 KB |
Output is correct |
17 |
Correct |
124 ms |
412 KB |
Output is correct |
18 |
Correct |
114 ms |
424 KB |
Output is correct |
19 |
Correct |
132 ms |
408 KB |
Output is correct |
20 |
Correct |
111 ms |
344 KB |
Output is correct |
21 |
Correct |
100 ms |
348 KB |
Output is correct |
22 |
Correct |
115 ms |
348 KB |
Output is correct |
23 |
Correct |
111 ms |
348 KB |
Output is correct |
24 |
Correct |
109 ms |
412 KB |
Output is correct |
25 |
Correct |
112 ms |
408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
344 KB |
Output is correct |
2 |
Correct |
113 ms |
412 KB |
Output is correct |
3 |
Correct |
108 ms |
344 KB |
Output is correct |
4 |
Correct |
115 ms |
416 KB |
Output is correct |
5 |
Correct |
113 ms |
408 KB |
Output is correct |
6 |
Correct |
110 ms |
600 KB |
Output is correct |
7 |
Correct |
115 ms |
416 KB |
Output is correct |
8 |
Correct |
112 ms |
412 KB |
Output is correct |
9 |
Correct |
112 ms |
348 KB |
Output is correct |
10 |
Correct |
111 ms |
344 KB |
Output is correct |
11 |
Correct |
113 ms |
348 KB |
Output is correct |
12 |
Correct |
114 ms |
344 KB |
Output is correct |
13 |
Correct |
112 ms |
348 KB |
Output is correct |
14 |
Correct |
111 ms |
412 KB |
Output is correct |
15 |
Correct |
110 ms |
416 KB |
Output is correct |
16 |
Correct |
113 ms |
412 KB |
Output is correct |
17 |
Correct |
124 ms |
412 KB |
Output is correct |
18 |
Correct |
114 ms |
424 KB |
Output is correct |
19 |
Correct |
132 ms |
408 KB |
Output is correct |
20 |
Correct |
111 ms |
344 KB |
Output is correct |
21 |
Correct |
100 ms |
348 KB |
Output is correct |
22 |
Correct |
115 ms |
348 KB |
Output is correct |
23 |
Correct |
111 ms |
348 KB |
Output is correct |
24 |
Correct |
109 ms |
412 KB |
Output is correct |
25 |
Correct |
112 ms |
408 KB |
Output is correct |
26 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
1160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
344 KB |
Output is correct |
2 |
Correct |
113 ms |
412 KB |
Output is correct |
3 |
Correct |
108 ms |
344 KB |
Output is correct |
4 |
Correct |
115 ms |
416 KB |
Output is correct |
5 |
Correct |
113 ms |
408 KB |
Output is correct |
6 |
Correct |
110 ms |
600 KB |
Output is correct |
7 |
Correct |
115 ms |
416 KB |
Output is correct |
8 |
Correct |
112 ms |
412 KB |
Output is correct |
9 |
Correct |
112 ms |
348 KB |
Output is correct |
10 |
Correct |
111 ms |
344 KB |
Output is correct |
11 |
Correct |
113 ms |
348 KB |
Output is correct |
12 |
Correct |
114 ms |
344 KB |
Output is correct |
13 |
Correct |
112 ms |
348 KB |
Output is correct |
14 |
Correct |
111 ms |
412 KB |
Output is correct |
15 |
Correct |
110 ms |
416 KB |
Output is correct |
16 |
Correct |
113 ms |
412 KB |
Output is correct |
17 |
Correct |
124 ms |
412 KB |
Output is correct |
18 |
Correct |
114 ms |
424 KB |
Output is correct |
19 |
Correct |
132 ms |
408 KB |
Output is correct |
20 |
Correct |
111 ms |
344 KB |
Output is correct |
21 |
Correct |
100 ms |
348 KB |
Output is correct |
22 |
Correct |
115 ms |
348 KB |
Output is correct |
23 |
Correct |
111 ms |
348 KB |
Output is correct |
24 |
Correct |
109 ms |
412 KB |
Output is correct |
25 |
Correct |
112 ms |
408 KB |
Output is correct |
26 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |