2 条题解
-
0
#include <bits/stdc++.h> using namespace std; #define ll long long bool comp(ll a, ll b) { return a > b; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); vector<ll> vec; ll count, temp; cin >> count; for (ll i = 0; i < count; i++) { cin >> temp; vec.push_back(temp); } sort(vec.begin(), vec.end(), comp); ll ans = 0, sum = accumulate(vec.begin(), vec.end(), 0); for (ll i = count - 1; i > 0; i--) { ans += sum; sum -= vec.at(i); vec.pop_back(); } cout << ans; return 0; }
-
0
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; typedef long long LL; int main() { int n; cin>>n; priority_queue<int,vector<int>,less<int>> q;//大根堆 for(int i=0;i<n;i++) { int x; cin>>x; q.push(x); } LL sum=0; LL cnt=0; cnt=q.top(); q.pop(); while(q.size()!=0) { cnt+=q.top();//计算一个每次计算叠加的值 sum+=cnt;//计算答案 q.pop(); } cout<<sum; return 0; }
- 1
信息
- ID
- 118
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 46
- 已通过
- 26
- 上传者