Need Help with RunTime Error

Revision en1, by exelover, 2017-05-20 18:39:10

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; }

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English exelover 2017-05-20 18:39:10 1291 Initial revision (published)