void dj(int p,int *d,bool *s,pq q){ for (int i=1;i<=n;i++) d[i]=inf; d[p]=0; q.push(make_pair(0,p)); // wu s[1]!! for (int z=1;z<=n;z++){ /*pii tmp=q.top();q.pop();//pop! while (!q.empty() && s[tmp.se]){ tmp=q.top();q.pop(); } if (s[tmp.se])//not q.empty()!!!!!!!!!!!!!!!!!!!!!!! abnormal stop!*/ if (q.empty()) break;//!!!!!!!!!!!!!! pii tmp=q.top();q.pop(); while (!q.empty() && s[tmp.se]){//!!!!!!! tmp=q.top();q.pop(); } int x=tmp.se; if (s[x]) break; s[x]=true; for (int i=hd[x];i;i=e[i].ne){ int y=e[i].v;//y not j! if (!s[y] && d[x]+e[i].w<d[y]){//!s! d[y]=d[x]+e[i].w; q.push(make_pair(d[y],y)); } } } }
int main() { a_it.push_back(q1.push(mp(1,1))); a_it.push_back(q1.push(mp(3,2))); a_it.push_back(q2.push(mp(2,3))); a_it.push_back(q2.push(mp(4,4))); cout<<q1.size()<<' '<<q2.size()<<endl; q1.join(q2); cout<<q1.size()<<' '<<q2.size()<<endl; cout<<q1.top().first<<' '<<q1.top().second<<endl; q1.modify(a_it[q1.top().second-1],mp(0,4)); cout<<q1.top().first<<' '<<q1.top().second<<endl; return 0; }
void dj(int p,int * d,int * s,pq q){ for(int i = 1;i<=n;++i) d[i] = INF; d[p] = 0;q.push(MP(0,p)); for(int z = 1;z<=n;++z){ if(q.empty()) break; pii tmp = q.top();q.pop(); while(!q.empty() && s[tmp.Y]) tmp = q.top(),q.pop(); int x = tmp.Y; if(s[x]) break; s[x] = 1; for(int i = hd[x];i;i=e[i].ne){ int y = e[i].v; if(!s[y] && d[y] > d[x]+e[i].w)d[y] = d[x]+e[i].w,q.push(MP(d[y],y)); } } }
int main(void) { long long num; cin >> num; long long sum = 0; for (long long i = 0; i < num; i++) { long long temp; cin >> temp; small.push(-temp); big.push(temp); sum += temp; } if (sum%num) { cout << "Impossible"; return 0; } long long count = 0; for (; ; ) { //cout << big.top() << " " << -small.top() << endl; if (-small.top() > big.top()) { cout << "Impossible"; break; } if (big.top()-1 == -small.top()) { cout << "Impossible"; break; } long long x = big.top(); if (big.top() == -small.top()) { cout << count << endl; break; } big.pop(); big.push(x-1); long long y = small.top(); small.pop(); small.push(y-1); count++; } }