2021牛客多校6 F
思路:
思路其实就是简单贪心…比赛时也想到了…但是在代码实现和取最大值的时候想歪了,导致没能写出来…
代码:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef double dd;
typedef pair<int, int> pii;
typedef pair<dd, dd> pdd;
const int MAXN = 100010;
const int MAXM = 10;
const int inf = 1e9 + 7;
const dd eps = 1e-9;
int n, m;
pair<ll,ll> a[MAXN];
ll pan[MAXN];
int main()
{
ll x = 0;
ll sum = 0;
cin >> n >> m;
for (int i = 1;i <= n;i++)
{
cin >> a[i].first;
x = max(a[i].first, x);
a[i].second = i;
sum += a[i].first;
}
//sort(a + 1, a + 1 + n, greater<pii>());
ll mx = max((sum - 1) / m + 1, x);
ll now = 1;
for (int i = 1;i <= n;i++)
{
if (pan[now] + a[i].first <= mx)
{
printf("1 %lld %lld %lld\n", now, pan[now], pan[now] + a[i].first);
pan[now] += a[i].first;
}
else
{
printf("2 %lld %lld %lld %lld %lld %lld\n", now + 1, 0ll, a[i].first - (mx - pan[now]), now, pan[now], mx);
pan[now + 1] += a[i].first - (mx - pan[now]);
now++;
}
if (pan[now] == mx) now++;
}
}