exelover's blog

By exelover, history, 7 years ago, In English
  • Vote: I like it
  • 0
  • Vote: I do not like it

By exelover, history, 8 years ago, In English

Hi! I attempted to do the problem http://codeforces.me/problemset/problem/808/C but got a runtime error with my solution saying that the "Exit code is -1073741819".Please can someone tell me what did I do wrong?

Here is my code:

include<bits/stdc++.h>

define MAXN 100010

define pb push_back

define mp make_pair

using namespace std; int cmpfunc (const void * a, const void * b) { return ( (int)a — (int)b ); } int main(){ int cap,n,w,sum=0; cin>>n>>w; map <int,int> arr; map<int,int> :: iterator it; int p[n]; for(int i=0;i<n;i++){ cin>>cap; arr.insert(pair<int,int> (cap,i));

p[i]=ceil(cap/2.0);
sum+=p[i];

} if(sum>w){ cout<<"-1"; } else { w=w-sum; it=arr.end(); for(;it!=arr.begin();it--){ if(w!=0){ if(w>=it->first/2){ p[it->second]=it->first; w-= (it->first-p[it->second]); } else { p[it->second]+=w; w=0; }

}
        else {
            break;
        }


    }
    for(int i=0;i<n;i++){
        cout<<p[i]<<" ";
    }

} return 0; }

Full text and comments »

  • Vote: I like it
  • -9
  • Vote: I do not like it