Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace Problem_2
- {
- class Program
- {
- static void Main( string[] args )
- {
- string[] lines = File.ReadAllLines( "input.txt" );
- int cases = Int32.Parse( lines[0] );
- string output = "";
- for ( int i = 1; i < lines.Length; i++ )
- {
- output += "Case #" + i + ": " + Solve( lines[i].Split( ' ' ) ) + "\r\n";
- }
- File.WriteAllText( "output.txt", output );
- }
- static int Solve( string[] rawData )
- {
- int[] scores = new int[rawData.Length - 3];
- for ( int i = 3; i < rawData.Length; i++ )
- scores[i - 3] = Int32.Parse( rawData[i] );
- int googlers = Int32.Parse( rawData[0] );
- int triplets = Int32.Parse( rawData[1] );
- int best = Int32.Parse( rawData[2] );
- int maxGooglers = 0;
- for ( int i = 0; i < scores.Length; i++ )
- {
- // First try without triplets
- for ( int s1 = 0; s1 <= 10; s1++ )
- for ( int s2 = 0; s2 <= 10; s2++ )
- for ( int s3 = 0; s3 <= 10; s3++ )
- {
- int sum = s1 + s2 + s3;
- if ( sum != scores[i] ) continue;
- if ( Math.Abs( s1 - s2 ) > 1 || Math.Abs( s2 - s3 ) > 1 || Math.Abs( s3 - s1 ) > 1 ) continue;
- if ( s1 == best || s2 == best || s3 == best )
- {
- maxGooglers++;
- goto next;
- }
- }
- // Then attempt WITH triplets
- for ( int s1 = 0; s1 <= 10; s1++ )
- for ( int s2 = 0; s2 <= 10; s2++ )
- for ( int s3 = 0; s3 <= 10; s3++ )
- {
- int sum = s1 + s2 + s3;
- if ( sum != scores[i] ) continue;
- if ( ( Math.Abs( s1 - s2 ) > 1 || Math.Abs( s2 - s3 ) > 1 || Math.Abs( s3 - s1 ) > 1 ) && triplets == 0 ) continue;
- if ( s1 == best || s2 == best || s3 == best )
- {
- maxGooglers++;
- triplets--;
- goto next;
- }
- }
- next:
- continue;
- }
- return maxGooglers;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement