- 合并果子
- 2017-10-20 20:14:52 @
只有第二组数据能过,其他都WA,请问怎么回事?
```cpp
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int num = 0;
cin >> num;
vector<int> piles;
for (int i = 0; i < num; ++i) {
int temp;
cin >> temp;
piles.push_back(temp);
}
if (num == 1) {
cout << piles[0];
return 0;
}
sort(piles.begin(), piles.end());
unsigned long temp = piles[0] + piles[1];
unsigned long result = temp;
for (int j = 2; j < num; ++j) {
temp = temp + piles[j];
result += temp;
}
cout << result;
system("pause");
}
```
0 条评论
目前还没有评论...