Блог пользователя exelover

Автор exelover, история, 7 лет назад, По-английски
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор exelover, история, 7 лет назад, По-английски

Hi! I attempted to do the problem http://codeforces.com/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; }

Полный текст и комментарии »

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится