fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n,r; cin >> n >> r;
  7. vector<int> a(n);
  8. int left=0,happy=0;
  9. for(int i=0;i<n;++i) {
  10. cin >> a[i];
  11. r-=a[i]/2;
  12. happy+=2*(a[i]/2);
  13. if(a[i]&1!=0) {
  14. ++left;
  15. }
  16. }
  17. if(left>r) {
  18. happy+=2*r-left;
  19. }
  20. else {
  21. happy+=left;
  22. }
  23. cout << happy << "\n";
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5280KB
stdin
4 5
3 1 1 3
stdout
6