CSES - Datatähti 2020 alku - Results
Submission details
Task:Mastot
Sender:Microwave Abuser
Submission time:2019-10-11 21:39:27 +0300
Language:C++11
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:63:12: error: 'x' was not declared in this scope
      while(x <= maxrange)
            ^

Code

//g++ -std=c++11 -O2 -Wall microwave.cpp -o microwave
#include <bits/stdc++.h>
using namespace std;

//Globals

//Funks

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//COMMENCE CODE

	unsigned int n;
	cin >> n;

	unsigned int ranges [n];
	for(unsigned int r = 0; r < n; r++)
	{
		cin >> ranges[r];
	}

	unsigned long priceToGetHere [n];
	priceToGetHere[0] = 0;
	priceToGetHere[n] = 9223372036854775807;

	unsigned int prices [n];
	for(unsigned int r = 1; r < n; r++)
	{
		cin >> prices[r];
		priceToGetHere[r] = 9223372036854775807;
	}

	//Input collected, lets do stuff

	unsigned int curPos = 0;
	prices[0] = 0;

	unsigned int setEnd = 0;
	unsigned int maxrange;
	unsigned long adj;

	while(priceToGetHere[n] != priceToGetHere[curPos])
	{
		maxrange = min(ranges[curPos], n - curPos);
		adj = priceToGetHere[curPos] + prices[curPos];

		if(adj < priceToGetHere[curPos+1])
		{
			for(unsigned int r = 1; r <= maxrange; r++)
			{
				priceToGetHere[curPos + r] = adj;
			}
			setEnd = maxrange;
		}
		else
		{
			for(unsigned int r = setEnd + 1; r <= maxrange; r++) //!
			{
				if(adj < priceToGetHere[curPos + r])
				{
					while(x <= maxrange)
					{
						priceToGetHere[curPos + r] = adj;
						r++;
					}
				}
			}
		}
		if(setEnd > 0)
		{
			setEnd--;
		}
	
		curPos++;
	}
	cout << priceToGetHere[n];
}