CSES - Datatähti 2017 alku - Results
Submission details
Task:Maalarit
Sender:while(false)
Submission time:2016-10-16 22:51:09 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp:1:20: fatal error: stdafx.h: No such file or directory
 #include "stdafx.h"
                    ^
compilation terminated.

Code

#include "stdafx.h"
#include <iostream>
#include <algorithm>
using namespace std;

int n;
long long x[100000];
int m[100000];
long long c[3];

int main()
{
	c[0] = 0;
	c[1] = 0;
	c[2] = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	long long a[3];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			a[j] = 0;
			if (i != 0 && m[i - 1] == j + 1) {
				a[j] += 1000000000000;
			}
			if (x[i] > c[j]) {
				a[j] += x[i] - c[j];
			}
			if (i < n - 1) {
				long long b[3];
				long long b1 = 1000000000000;
				for (int k = 0; k < 3; k++) {
					b[k] = 0;
					if (j == k) {
						b[k] += 1000000000000;
					}
					if (x[i + 1] > c[k]) {
						b[k] += x[i+1] - c[k];
					}
					if (i + 1 < n - 1) {
						long long d[3];
						long long d1 = 1000000000000;
						for (int l = 0; l < 3; l++) {
							d[l] = 0;
							if (k == l) {
								d[l] += 1000000000000;
							}
							if (x[i + 2] > c[l] + a[l]) {
								d[l] += x[i + 2] - c[l]- a[l];
							}
						}
						if (d1 > d[0]) { d1 = d[0]; }
						if (d1 > d[1]) { d1 = d[1]; }
						if (d1 > d[2]) { d1 = d[2]; }
						b[k] += d1;
					}
				}
				if (b1 > b[0]) { b1 = b[0]; }
				if (b1 > b[1]) { b1 = b[1]; }
				if (b1 > b[2]) { b1 = b[2]; }
				a[j] += b1;
			}
		}
		if (a[0] <= a[1] && a[0] <= a[2]) { m[i] = 1; }
		else if (a[1] <= a[2]) { m[i] = 2; }
		else { m[i] = 3; }
		if (x[i] > c[m[i]-1]) {
			c[m[i] - 1] = x[i];
		}
	}

	int k = 3;
	if (c[2] == 0) { k = 2; }
	if (c[1] == 0) { k = 1; }
	cout << c[0] + c[1] + c[2] << ' ' << k << '\n';
	for (int i = 0; i < n; i++) {
		printf("%i ", m[i]);
	}
	cin >> n;
	return 0;
}