Created
October 30, 2016 07:04
-
-
Save ia7ck/a6718c1f035af03ca11cbee11777e843 to your computer and use it in GitHub Desktop.
CODE FESTIVAL 2015 チーム対抗 I-Platoon Match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<algorithm> | |
using namespace std; | |
int dp[200*200*2]; | |
int main(){ | |
int N; | |
cin>> N; | |
int k[N], d[N]; | |
for(int i=0; i<N; i++){ | |
cin>> k[i]>> d[i]; | |
} | |
int sk=accumulate(k, k+N, 0); | |
if(sk!=accumulate(d, d+N, 0)){ | |
cout<< "invalid"<< endl; | |
return 0; | |
} | |
dp[0]=1; | |
for(int i=0; i<N; i++){ | |
for(int sB=sk; sB>=0; sB--){ | |
dp[d[i]+k[i]+sB]|=dp[sB]; | |
} | |
} | |
cout<< (dp[sk]?"valid":"invalid")<< endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment