第1行:1个整数N(2 <= N <= 50000)第2 - N + 1行:每行1个整数Li(1 <= Li <= 1000)。Output输出最小的体力消耗。Input示例3345Output示例19思路:
优先队列水题。代码:
#include <bits/stdc++.h>using namespace std;const int MAXN = 1e5 + 10;int a[MAXN];int main() { int n; scanf("%d", &n); PRiority_queue <int, vector <int>, greater <int> > que; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); que.push(a[i]); } int ans = 0; while (que.size() > 1) { int x = que.top(); que.pop(); int y = que.top(); que.pop(); que.push(x + y); ans += x + y; } printf("%d/n", ans); return 0;}
新闻热点
疑难解答