Submission #628643

#TimeUsernameProblemLanguageResultExecution timeMemory
628643a_aguiloTug of War (BOI15_tug)C++17
18 / 100
3091 ms2004 KiB
#include<bits/stdc++.h> using namespace std; typedef vector<int> vi; vi leftSpots, rightSpots; struct contestant{ int left, right, force; contestant(int l, int r, int f){ left = l; right = r; force = f; } }; vector<contestant*> people; int n, k; int sLeft, sRight; bool possible(int pos){ if(pos == 2*n) return (abs(sLeft-sRight)<= k); if(!leftSpots[people[pos]->left]){ sLeft += people[pos]->force; leftSpots[people[pos]->left] = 1; if(possible(pos+1)) return true; sLeft -= people[pos]->force; leftSpots[people[pos]->left] = 0; } if(!rightSpots[people[pos]->right]){ sRight += people[pos]->force; rightSpots[people[pos]->right] = 1; if(possible(pos+1)) return true; sRight -= people[pos]->force; rightSpots[people[pos]->right] = 0; } return false; } int main(){ int l, r, s; cin >> n >> k; people = vector<contestant*> (2*n); for(int i = 0; i < 2*n; ++i){ cin >> l >> r >> s; l--; r--; contestant* act = new contestant(l, r, s); people[i] = act; } sLeft = 0; sRight = 0; leftSpots = vi(n, 0); rightSpots = vi(n, 0); if(possible(0)) 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...