$\color{aqua}\text{Runtime Error!!!}$

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

```cpp while(que.size()>=1) ``` 改为 ```cpp while(que.size()>1) ```
by qwasd @ 2022-09-30 08:45:42


@[qwasd](/user/484970) 感谢神犇!!!
by Allen_yang @ 2022-09-30 08:47:42


可是为什么在本地样例过了,[IDE](https://www.luogu.com.cn/ide)里却没过
by Allen_yang @ 2022-09-30 08:51:30


给那些各位大佬,把代码改成: ``` #include<iostream> #include<queue> using namespace std; int main(){ priority_queue<int,vector<int>,greater<int> > que; int n,ans=0; cin >> n; for(int i=1;i<=n;i++){ int a; cin >> a; que.push(a); } while(que.size()>1){ int p=que.top(); que.pop(); int q=que.top(); que.pop(); que.push(p+q); ans+=q+p; } cout << ans; return 0; } ``` 就AC了。
by Allen_yang @ 2022-09-30 09:10:19


btd
by miaowu_ @ 2022-10-19 20:03:52


|