UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201552#3496. mergehjk100840ms3152kbC++11610b2024-02-01 10:26:442024-02-01 12:12:19

answer

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
priority_queue<ll,vector<ll>,greater<ll>> q;
ll n,k,x,ans;
int main() {
	cin>>n>>k;
	for(int i=1; i<=n; i++) {
		cin>>x;
		q.push(x);
	}
	while(q.size()) {
		ll cnt=0;
		if((n-1)%(k-1)==0){
			for(int i=1; q.size()&&i<=k; i++) {
				cnt+=q.top();
				q.pop();
			}			
		}
		else{
			for(int i=1; q.size()&&i<=((n-1)%(k-1))+1; i++) {
				cnt+=q.top();
				q.pop();
				
			}
			n-=((n-1)%(k-1));
		}
		ans+=cnt;
		if(q.size()) {
			q.push(cnt);
		}
	}
	cout<<ans;
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 91ms
memory: 3152kb

input:

150000 2
434583212 116256481 589268552 163243281 285130344 992105295 893298044 138961434 539544476 2...

output:

1182187758113640

result:

ok single line: '1182187758113640'

Test #2:

score: 10
Accepted
time: 92ms
memory: 3148kb

input:

150000 2
985257033 712483639 139240697 827869119 686984103 77116890 125712755 795962568 557028813 87...

output:

1183863800694958

result:

ok single line: '1183863800694958'

Test #3:

score: 10
Accepted
time: 84ms
memory: 3148kb

input:

150000 2
60722066 712322645 204600125 837413405 46547263 333048073 718069801 888455630 590156020 952...

output:

1182705078181480

result:

ok single line: '1182705078181480'

Test #4:

score: 10
Accepted
time: 65ms
memory: 3152kb

input:

150063 419
13367245 88398172 983219812 365718766 306349993 87613356 810798954 159066632 638405310 13...

output:

140302376916196

result:

ok single line: '140302376916196'

Test #5:

score: 10
Accepted
time: 75ms
memory: 3152kb

input:

150067 379
70745968 682399015 711351205 7930360 140656827 318322799 186739170 812628678 965816275 81...

output:

141153693815572

result:

ok single line: '141153693815572'

Test #6:

score: 10
Accepted
time: 68ms
memory: 3152kb

input:

150101 396
101264972 589252159 835851376 29695095 259158069 955567501 161908542 388233547 518426060 ...

output:

140341912106343

result:

ok single line: '140341912106343'

Test #7:

score: 10
Accepted
time: 95ms
memory: 3152kb

input:

190367 416
147886208 441234333 640088574 258549524 878712921 804366782 540630650 814741869 909920623...

output:

178925710567049

result:

ok single line: '178925710567049'

Test #8:

score: 10
Accepted
time: 95ms
memory: 3152kb

input:

177658 379
198778386 793896719 804007432 115569623 580275274 977434187 335723107 860383843 933557039...

output:

167916995251604

result:

ok single line: '167916995251604'

Test #9:

score: 10
Accepted
time: 92ms
memory: 3152kb

input:

194118 356
900255373 384561011 778947555 396308808 390092230 606873578 687992131 428453478 770122855...

output:

189993739354498

result:

ok single line: '189993739354498'

Test #10:

score: 10
Accepted
time: 83ms
memory: 3148kb

input:

157415 373
64151020 185493808 460983001 813731001 704176218 145376893 391577420 682045793 887449048 ...

output:

148053601799752

result:

ok single line: '148053601799752'