Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- int n;
- fin >> n;
- vector<int> vec(n);
- int sum = 0;
- for (int i = 0; i < vec.size(); i++) {
- fin >> vec[i];
- sum += vec[i];
- }
- if (sum % 2 == 1) {
- fout << "NO" << endl;
- fin.close();
- fout.close();
- return 0;
- }
- vector<bool> answ(sum + 1);
- answ[0] = 1;
- for (int i = 0; i < n; i++)
- for (int j = sum - vec[i]; j >= 0; j--)
- if (answ[j]) answ[j + vec[i]] = 1;
- fout << (answ[sum / 2] ? "YES" : "NO") << endl;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment