This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |