Translate

Views

Wednesday, June 1, 2022

Solution Kattis - Amalgamated Artichokes

 Source: https://open.kattis.com/problems/artichoke


Don't worry if you don't know C# because it's quite similar to C++, Java


Submission

IDDATEPROBLEMSTATUSCPULANG
TEST CASES
901442101:08:19Amalgamated ArtichokesAccepted0.14 sC#

Submission contains 1 file: download zip archive

FILENAMEFILESIZESHA-1 SUM
artichoke.cs1044 bytes9b556c241ecfb038e69b55e5dd3917b53f2b84f6download

Edit and resubmit this submission.

artichoke.cs

using System;
class Program
{
double[] dp = new double[1000111];
double[] price = new double[1000111];
int p, a, b, c, d, n, k;
Program()
{
string[] s = Console.ReadLine().Split(" ");
p = Convert.ToInt32(s[0]);
a = Convert.ToInt32(s[1]);
b = Convert.ToInt32(s[2]);
c = Convert.ToInt32(s[3]);
d = Convert.ToInt32(s[4]);
n = Convert.ToInt32(s[5]);
k=0;
while (k < n)
{
price[++k] = p * (Math.Sin(a * k + b) + Math.Cos(c * k + d) + 2);
}
dp[n] = price[n];
for(int i=n-1; i>=1; i--)
dp[i]= Math.Min(price[i], dp[i+1]);
double declineMAX = 0, MAX = Double.MinValue;
for (int i = 1; i <= n; i++)
{
MAX= Math.Max(MAX, price[i]);
declineMAX = Math.Max(MAX - dp[i], declineMAX);
}
Console.WriteLine(declineMAX);
}
public static void Main(string[] args)
{
new Program();
}
}

No comments: