这样不对吗。..
查看原帖
这样不对吗。..
1068985
Hopoyage楼主2024/4/12 08:34
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
#define pii pair<int, int>
int ne[N];
int main()
{
	memset(ne, -1, sizeof ne);
	priority_queue<pii, vector<pii>, greater<pii>> heap;
	int n, m;
	cin >> n >> m;

	if (m > n)
	{
		for (int i = 1; i <= n; i++)
		{
			int t;
			cin >> t;
			heap.push({t, i});
		}
		for (int i = n + 1; i <= m; i++)
		{
			int t;
			cin >> t;
			pii a = heap.top();
			heap.pop();
			ne[a.second] = i;
			heap.push({a.first + t, i});

			//cout << "ne[" << a.second << "] = " << i << endl;
		}
		for (int i = 1; i <= n; i++)
		{
			int now = i;
			cout << now << " ";
			while (1)
			{
				now = ne[now];
				if (now == -1)
					break;
				cout << now << " ";
			}
			puts("");
		}
	}
	else
	{
		if (n == m)
		{
			for (int i = 1; i <= n; i++)
			{
				int t;cin >> t;
				cout << i << " ";
			}
		}
		else
		{
			for (int i = 1; i <= m; i++)
			{
				int t;cin >> t;
				cout << i << endl;
			}
			for (int i = m + 1; i <= n; i++)
			{
				cout << 0 << endl;
			}
		}
	}
	return 0;
}
2024/4/12 08:34
加载中...