nullzero

World

Jul 24th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2.  
  3. class world{
  4.     static void Main(){
  5.         string input = Console.ReadLine();
  6.         string[] sinput1 = input.Split(' ');
  7.         int n = int.Parse(sinput1[0]);
  8.         int k = int.Parse(sinput1[1]);
  9.         input = Console.ReadLine();
  10.         string[] sinput2 = input.Split(' ');
  11.         int[] seq = new int[sinput2.Length];
  12.         for(int i = 0; i < n; i++) seq[i] = int.Parse(sinput2[i]);
  13.        
  14.         bool found = false;
  15.         int l = 0, r = 0;
  16.         int sum = seq[0];
  17.         while(l < n){
  18.             if(l > r){
  19.                 sum = seq[l];
  20.                 r = l;
  21.             }
  22.             if(sum == k){
  23.                 found = true;
  24.                 break;
  25.             }
  26.             if(r < n - 1 && sum + seq[r + 1] <= k){
  27.                 r++;
  28.                 sum += seq[r];
  29.             }else{
  30.                 sum -= seq[l];
  31.                 l++;
  32.             }
  33.         }
  34.         Console.WriteLine(found ? "World" : "No");
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment