QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225967 | #3138. Length of Bundle Rope | Abtahi# | AC ✓ | 1ms | 3836kb | C++17 | 1.1kb | 2023-10-25 13:29:58 | 2023-10-25 13:29:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef unordered_map<int,int> umap;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define popcount __builtin_popcount
#define case cout<<"Case "<<__testcase-testcase<<": ";
#define endl '\n'
#define INF 1e18
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int testcase=1;
cin>>testcase;
int __testcase=testcase;
while(testcase--){
int n;
cin>>n;
ll a[n];
for(int i=0;i<n;i++) cin>>a[i];
multiset<ll> ms;
for(int i=0;i<n;i++) ms.insert(a[i]);
ll ans=0;
while(ms.size()){
ll tp=*ms.begin();
//ans+=tp;
ms.erase(ms.find(tp));
if(ms.size()){
ll tp2=*ms.begin();
ms.erase(ms.find(tp2));
ans+=tp+tp2;
ms.insert(tp+tp2);
}
}
cout<<ans<<endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
input:
4 6 2 3 4 4 5 7 5 5 15 40 30 10 10 3 1 5 4 8 2 6 1 1 2 9 3 2 1 6 5 2 6 4 3
output:
63 205 100 98
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
10 317 433 571 952 914 928 387 359 997 381 987 801 614 17 897 225 24 451 874 281 615 417 629 61 258 339 935 907 112 706 880 646 879 257 502 795 739 715 440 843 373 757 974 866 284 437 624 575 680 732 604 669 740 352 324 818 603 893 127 310 143 364 238 534 926 572 273 858 814 393 348 91 2 554 293 465...
output:
1249288 2229139 2550728 444394 243473 1034499 2418139 4488000 4862448 9976
result:
ok 10 lines