-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilemerging.cpp
More file actions
37 lines (29 loc) · 12.8 KB
/
Copy pathFilemerging.cpp
File metadata and controls
37 lines (29 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<bits/stdc++.h>
using namespace std;
void merge(vector<int>&arr){
priority_queue<int,vector<int>,greater<int>>pq;
for(int i:arr){
pq.push(i);
}
int prev = 0;
int ans = 0;
while(!pq.empty()){
int top = pq.top();
ans += prev + top;
prev = ans;
}
cout<<ans<<endl;
}
int main(){
int n;
cout<<"enter no of files:"<<endl;
cin>>n;
vector<int>file(n,0);
for(int i = 0;i< file.size();i++){
cin>>file[i];
}
merge(file);
return 0;
}
return 0;
}