Submission #890756

#TimeUsernameProblemLanguageResultExecution timeMemory
890756zeta7532Tug of War (BOI15_tug)C++17
18 / 100
132 ms1160 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...