grukas

Munka(jó)

Jan 3rd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //using System.IO;
  6.  
  7. namespace munka
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //StreamReader be = new StreamReader("in.5");
  14.             //Console.SetIn(be);
  15.  
  16.             string[] line = Console.ReadLine().Split(' ');
  17.             int N = int.Parse(line[0]);
  18.             int F = int.Parse(line[1]);
  19.             int sumF = 0;
  20.             int temp_tol = 0, temp_ig = 0;
  21.             int cnt2 = 0;
  22.             int jo_tol = -1;
  23.             int jo_ig = 0;
  24.             int cnt = 0;
  25.             int legkevesebb = -1;
  26.  
  27.             List<int> jov = new List<int>();
  28.             for (int i=0; i<N; i++)
  29.                 jov.Add(int.Parse(Console.ReadLine()));
  30.             jov.Add(0);
  31.             //be.Close();    
  32.             bool done = false;
  33.             //StreamWriter ki = new StreamWriter("ki.txt");
  34.             //Console.SetOut(ki);
  35.  
  36.             while (cnt < N)
  37.             {
  38.                 while (cnt2 < N && done == false)
  39.                 {
  40.                     sumF += jov[cnt2];
  41.                     if (sumF >= F)
  42.                     {
  43.                         done = true;
  44.                         temp_tol = cnt;
  45.                         temp_ig = cnt2;
  46.                         if (legkevesebb == -1 || cnt2 - cnt < legkevesebb)
  47.                         {
  48.                             jo_tol = temp_tol;
  49.                             jo_ig = temp_ig;
  50.                             legkevesebb = jo_ig - jo_tol;
  51.                         }
  52.                     }
  53.                     cnt2++;
  54.                 }
  55.                 cnt++;
  56.                 cnt2 = cnt;
  57.                 done = false;
  58.                 sumF = 0;
  59.             }
  60.  
  61.             if (jo_tol == -1)
  62.                 Console.WriteLine("{0} {1}", -1, -1);
  63.             else
  64.                 Console.WriteLine("{0} {1}", jo_tol+1, jo_ig+1);
  65.  
  66.            
  67.             //ki.Close();
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment