Submission #237068

# Submission time Handle Problem Language Result Execution time Memory
237068 2020-06-04T11:47:45 Z MrRobot_28 Hokej (COCI17_hokej) C++17
120 / 120
493 ms 24484 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
bool cmp(pair <int, pair <int, int> > a, pair <int, pair <int, int> > b)
{
	if(a.first == b.first)
	{
		return a.second.first > b.second.first;
	}
	return a.first < b.first;
}
signed main() {
	int m, n;
	cin >> m >> n;
	vector <pair <pair <int, int>, int> > x(n);
	for(int i = 0; i < n; i++){
		cin >> x[i].first.first >> x[i].first.second;
		x[i].second = i;
	}
	sort(x.begin(), x.end());
	reverse(x.begin(), x.end());
	int sum = 0;
	vector <pair <int, pair <int, int> > > ans;
	vector <int> start(6);
	int timer = 0;
	int cnt = 1;
	vector <int> allsum(n);
	for(int i = 0; i < n; i++)
	{
		if(timer == 0)
		{
			allsum[x[i].second] = x[i].first.second;
			sum += x[i].first.second * x[i].first.first;
			timer += x[i].first.second;
		}
		else if(timer + x[i].first.second > m){
			allsum[x[i].second] += m - timer;
			sum +=(m - timer)* x[i].first.first; 
			if(cnt == 6)
			{
				timer = m;
			}
			else
			{
				cnt++;
				allsum[x[i].second] += x[i].first.second - (m - timer);
				timer = x[i].first.second - (m - timer);
				sum += timer * x[i].first.first;
			}
		}
		else{
			sum += x[i].first.second * x[i].first.first;
			allsum[x[i].second] = x[i].first.second;
			timer += x[i].first.second;
		}
		if(cnt == 6 && timer == m)
		{
			break;
		}
	}
	vector <pair <int, int> > p;
	for(int i = 0; i < n; i++)
	{
		p.push_back({allsum[i], i});
	}
	sort(p.begin(), p.end());
	reverse(p.begin(), p.end());
	timer = 0;
	cnt = 1;
	for(int i = 0; i < p.size(); i++)
	{
		if(p[i].first == 0)
		{
			break;
		}
		int v = p[i].second;
		if(timer == 0)
		{
			timer += p[i].first;
			start[cnt - 1] = p[i].second;
		}
		else if(timer + p[i].first > m)
		{
			ans.push_back({timer, {p[i - 1].second, p[i].second}});
			timer = p[i].first - (m - timer);
			cnt++;
			start[cnt - 1] = p[i].second;
		}
		else
		{
			ans.push_back({timer, {p[i - 1].second, p[i].second}});
			timer += p[i].first;
		}
		if(timer == m)
		{
			timer = 0;
			cnt++;
		}
	}
	cout << sum << "\n";
	for(int i = 0; i < 6; i++)
	{
		cout << start[i] + 1<< " ";
	}
	cout << "\n";
	cout << ans.size() << "\n";
	sort(ans.begin(), ans.end(), cmp);
	for(int i = 0; i < ans.size(); i++)
	{
		cout << ans[i].first << " " << ans[i].second.first + 1 << " " << ans[i].second.second + 1 << "\n";
	}
    return 0;
}

Compilation message

hokej.cpp: In function 'int main()':
hokej.cpp:70:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i++)
                 ~~^~~~~~~~~~
hokej.cpp:76:7: warning: unused variable 'v' [-Wunused-variable]
   int v = p[i].second;
       ^
hokej.cpp:108:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ans.size(); i++)
                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 12 ms 768 KB Output is correct
3 Correct 30 ms 1788 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 14 ms 1152 KB Output is correct
6 Correct 9 ms 640 KB Output is correct
7 Correct 12 ms 1024 KB Output is correct
8 Correct 89 ms 5744 KB Output is correct
9 Correct 492 ms 24484 KB Output is correct
10 Correct 493 ms 24472 KB Output is correct