|
|
вернуться в форумNew test My solution of 1005 problem was accepted. Here it is: #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n,t; vector<int> w; cin >> n; for(int i = 0; i < n; ++i) { cin >> t; w.push_back(t); } sort(w.begin(), w.end()); vector<int>::reverse_iterator it = w.rbegin(); vector<int>::reverse_iterator end = w.rend(); int s = 0; for(; it != end; ++it) s += *it; it = w.rbegin(); s = s/2 + (s%2); int l = 0, r = 0; for(; it != end; ++it) if(l + *it <= s) l += *it; else r += *it; cout << abs(l-r) << endl; return 0; } But there is a test, where this solution gives a wrong answer: 6 101 51 51 3 2 2 Re: New test Yeah, right answer is 0, but your 2.. I hope that admins will add some new tests. Edited by author 11.08.2012 20:16 |
|
|