#include using namespace std; typedef long long ll; char s[11111]; struct node { int a,b; bool operator<(const node&p)const { return a=0;i--) { while(A[i].b) { if(total+A[i].a>=0) { sum+=total+A[i].a; total+=A[i].a; } else { flag=1; break; } A[i].b--; } if(flag) break; } printf("%I64d\n",sum); } return 0; }