2022-05-19每日刷题打卡

2022-05-19每日刷题打卡

代码源——每日一题

贪就是了 - 题目 - Daimayuan Online Judge
题目描述

给你一个序列 aa,我们定义

S(l,r)=∑i=li=rai

, 显然易见我们会有n∗(n+1)/2个不同的Sl,r,请你输出其中前 k大的Sl,r

输入描述

第一行输入两个整数 n,k 第二行输入 n个整数代表序列 a

输出描述

输出一行包含 k个整数代表答案

样例输入1
6 8
1 1 4 5 1 4
样例输出1
16 15 14 12 11 11 10 10
数据范围

0≤ai≤10e9,1≤n≤10e5,1≤k≤min(10e5,n∗(n+1)/2)

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>

#define endl '\n'
#define int ll
typedef long long ll;
typedef pair<ll, ll>PII;
const int N = 1e6 + 50;
int n, k;
int a[N];
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
 
    priority_queue<pair<ll, int>> que;
	ll sum = 0;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
	{
		cin>>a[i];
		sum += a[i];
		que.push({ sum,1 });
	}
	for (int i = 1; i <= k; ++i)
	{
		ll res = que.top().first;
		int j = que.top().second;
		cout << res << " ";
		que.pop();
		if (res - a[j] <= 0)	continue;
		que.push({ res - a[j],j + 1 });
	}
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值