이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |