Submission #80889

# Submission time Handle Problem Language Result Execution time Memory
80889 2018-10-22T17:24:21 Z MatheusLealV Hokej (COCI17_hokej) C++17
72 / 120
252 ms 28660 KB
#include <bits/stdc++.h>
#define N 500050
#define int long long
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;

struct T
{
	int f, s, id;

} v[N];

bool cmp(T A, T B)
{
	return A.f > B.f;
}

int n, m, limite[N];

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>m>>n;

	for(int i = 1; i <= n; i++)
	{
		cin>>v[i].f>>v[i].s;

		v[i].id = i;
	}

	for(int i = 1; i <= n; i++) limite[i] = 1000000000;

	sort(v + 1, v + n + 1, cmp);

	stack<T> fila;

	for(int i = n; i >= 1; i--) fila.push(v[i]);

	int total = 0, sub = 0, ans = 0, tempo = 0;

	vector<T> subs;

	int ant = -1;

	while(!fila.empty() and total < 6*m)
	{
		int qual = fila.top().f, resta = fila.top().s, id = fila.top().id;

		fila.pop();

		if(sub + resta > m)
		{
			ans += (m - sub) * qual;

			total += (m - sub);

			if(resta - (m - sub) > 0) fila.push({qual, resta - (m - sub), id});

			sub = 0;

			subs.push_back({tempo, ant, id});

			ant = -1;

			tempo = 0;

			continue;
		}

		sub += resta;

		total += resta;

		ans += qual * resta;

		subs.push_back({tempo, ant, id});

		tempo += resta;

		if(sub == m)
		{
			sub = 0;

			ant = -1;

			tempo = 0;

			continue;
		}

		ant = id;
	}

	cout<<ans<<"\n";

	sort(subs.begin(), subs.end(), cmp);

	reverse(subs.begin(), subs.end());

	for(int i = 0; i < 6; i++) cout<<subs[i].id<<" \n"[i == 5];

	cout<<max(0LL, (int)subs.size() - 6LL)<<"\n";

	for(int i = 6; i < subs.size(); i++)
	{
		auto x = subs[i];

		cout<<x.f<<" "<<x.s<<" "<<x.id<<"\n";
	}
}

Compilation message

hokej.cpp: In function 'int32_t main()':
hokej.cpp:108:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 6; i < subs.size(); i++)
                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 5 ms 884 KB Output is correct
3 Correct 11 ms 1992 KB Output is correct
4 Correct 2 ms 1992 KB Output is correct
5 Correct 6 ms 1992 KB Output is correct
6 Correct 3 ms 1992 KB Output is correct
7 Incorrect 5 ms 1992 KB Output isn't correct
8 Incorrect 41 ms 6408 KB Output isn't correct
9 Incorrect 217 ms 28660 KB Output isn't correct
10 Incorrect 252 ms 28660 KB Output isn't correct