50pts直接爆TLE

P1090 [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G

你复杂度 $O(n^2 \log n)$,不 TLE 是什么。 ```cpp #include <bits/stdc++.h> using namespace std; priority_queue<int,vector<int>,greater<int> > q; int n,x,ans = 0; int main(){ scanf("%d",&n); for (int i = 1; i <= n; i++) scanf("%d",&x),q.push(x); for (int i = 2; i <= n; i++) { int x1 = q.top(); q.pop(); int x2 = q.top(); q.pop(); int sum = x1 + x2; ans += sum; q.push(sum); } printf("%d",ans); return 0; } ``` 我的优先队列 $43$ ms 秒杀。
by liuruiqing @ 2024-03-23 15:30:41


@[Leo_Lyc](/user/1052917) 把O2 优化打开就可以了
by lzaytyj @ 2024-03-23 15:43:52


@[lzaytyj](/user/1235091) @[liuruiqing](/user/1118614) thx!
by Leo_Lyc @ 2024-03-25 20:56:18


@[Leo_Lyc](/user/1052917) 啥意思
by lzaytyj @ 2024-03-27 22:34:08


这题优先队列是最好的做法,不接受反驳
by remake1958 @ 2024-04-03 18:27:29


@[lzaytyj](/user/1235091) thx=than - ks=thanks x=/ks/
by Leo_Lyc @ 2024-04-06 14:31:16


@[remake1958](/user/1272803) 我也是这么做的
by Mathhew @ 2024-05-03 12:14:17


|