Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace poging1{
  5.  
  6.     public class Program{
  7.  
  8.         public static void Main(string[] args){
  9.            
  10.             int i = Int32.Parse(Console.ReadLine());
  11.             string oautput = "";
  12.  
  13.             for (int j = 0; j < i; j++){
  14.  
  15.                 int n = Int32.Parse(Console.ReadLine());
  16.                
  17.                 string inpit = Console.ReadLine();
  18.                 string[] inpuot = inpit.Split(' ');
  19.                
  20.                 while(inpuot.Length != n){
  21.                     inpit = Console.ReadLine();
  22.                     string[] aprot = inpit.Split(' ');
  23.                     string[] tamp = new string[aprot.Length + inpuot.Length];
  24.                     inpuot.CopyTo(tamp, 0);
  25.                     aprot.CopyTo(tamp, inpuot.Length);
  26.                     inpuot = tamp;
  27.                    
  28.  
  29.                 }
  30.                 int[] input = new int[inpuot.Length];
  31.                
  32.  
  33.  
  34.  
  35.  
  36.  
  37.                 for(int m = 0; m < n; m++){
  38.  
  39.                     input[m] = Int32.Parse(inpuot[m]);      
  40.                 }
  41.  
  42.                 int[] outputt = rec(input, 0, input.Length-1);
  43.  
  44.                 oautput += outputt[2] + " " + outputt[0] + " " + outputt[1] + "\n";
  45.  
  46.                
  47.  
  48.                
  49.  
  50.             }
  51.             Console.WriteLine(oautput);
  52.  
  53.         }
  54.         public static int[] rec(int[] arr, int l, int r){
  55.  
  56.             //pos1, pos2, diff, minpos, maxpos
  57.             if(r-l == 0){
  58.                 return new int[]{l,l,0,l,l};
  59.             }
  60.  
  61.             if(r-l <= 1){
  62.  
  63.                 if(arr[r]>arr[l]){
  64.                     return new int[]{l,r,arr[l]-arr[r],l, r};
  65.                 }
  66.                
  67.                 return new int[]{l,r,arr[l]-arr[r],r, l};
  68.             }
  69.  
  70.            
  71.  
  72.             int[] links = rec(arr, l, l + ((r-l)/2));
  73.            
  74.             int[] rechts = rec(arr, l + ((r-l)/2) + 1, r);
  75.             int diffL = links[2];
  76.             int diffR = rechts[2];
  77.             int diffB = arr[links[4]] - arr[rechts[3]];
  78.             int min = 0;
  79.             if(arr[links[3]] > arr[rechts[3]]){
  80.                 min = rechts[3];
  81.             }
  82.             else{
  83.                 min = links[3];
  84.             }
  85.             int max = 0;
  86.             if(arr[links[4]] < arr[rechts[4]]){
  87.                 max = rechts[4];
  88.             }
  89.             else{
  90.                 max = links[4];
  91.             }
  92.  
  93.             if(diffL > diffR && diffL > diffB){
  94.                 return new int[]{links[0], links[1], links[2], min, max};
  95.             }
  96.             if(diffR > diffL && diffR > diffB){
  97.                 return new int[]{rechts[0], rechts[1], rechts[2], min, max};
  98.             }
  99.             return new int[]{links[4], rechts[3], arr[links[4]] - arr[rechts[3]], min, max};
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement