如果您用的优先队列且WA了
请检查
while(q.size() >= 2) { int x = q.top(); q.pop(); int y = q.top(); q.pop(); ans += x + y; q.push(ans); //!!! }
此处应为
q.push(x + y);