Advertisement
ivandrofly

Porcupine Fever (codingame)

Mar 5th, 2021
1,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8. /**
  9.  * Auto-generated code below aims at helping you parse
  10.  * the standard input according to the problem statement.
  11.  **/
  12. class Solution
  13. {
  14.     static void Main(string[] args)
  15.     {
  16.         int N = int.Parse(Console.ReadLine());
  17.         int Y = int.Parse(Console.ReadLine());
  18.  
  19.         // 0:
  20.  
  21.         // row represents cages
  22.         long[,] data = new long[N, 3];
  23.  
  24.         for (int  i = 0; i < N; i++)
  25.         {
  26.             string[] inputs = Console.ReadLine().Split(' ');
  27.             long S = long.Parse(inputs[0]);
  28.             long H = long.Parse(inputs[1]);
  29.             long A = long.Parse(inputs[2]);
  30.  
  31.             data[i, 0] = S;
  32.             data[i, 1] = H;
  33.             data[i, 2] = A; // = S  + H
  34.         }
  35.  
  36.         // Console.Error.WriteLine("total: + " + data.GetLength(0));
  37.         // Console.Error.WriteLine("year: + " + Y);
  38.  
  39.         for (int i = 0; i < Y; i++)
  40.         {
  41.             long total = 0;
  42.             for (int j = 0; j < N; j++)
  43.             {
  44.                 // s=sick, h=healthy, a=alive (a = s+h)
  45.                 data[j, 2] -= data[j, 0];
  46.                 data[j, 0] = data[j, 0] * 2;
  47.                 data[j, 1] -= data[j, 0];
  48.  
  49.                 total += data[j, 2] > 0 ? data[j, 2] : 0;
  50.             }
  51.  
  52.             Console.WriteLine(total);
  53.             if (total == 0)
  54.             {
  55.                 break;
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement