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
ID | DATE | PROBLEM | STATUS | CPU | LANG |
---|---|---|---|---|---|
TEST CASES | |||||
9014421 | 01:08:19 | Amalgamated Artichokes | Accepted | 0.14 s | C# |
FILENAME | FILESIZE | SHA-1 SUM | |
---|---|---|---|
artichoke.cs | 1044 bytes | 9b556c241ecfb038e69b55e5dd3917b53f2b84f6 | download |
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:
Post a Comment