Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace poging1{
- public class Program{
- public static void Main(string[] args){
- int i = Int32.Parse(Console.ReadLine());
- string oautput = "";
- for (int j = 0; j < i; j++){
- int n = Int32.Parse(Console.ReadLine());
- string inpit = Console.ReadLine();
- string[] inpuot = inpit.Split(' ');
- while(inpuot.Length != n){
- inpit = Console.ReadLine();
- string[] aprot = inpit.Split(' ');
- string[] tamp = new string[aprot.Length + inpuot.Length];
- inpuot.CopyTo(tamp, 0);
- aprot.CopyTo(tamp, inpuot.Length);
- inpuot = tamp;
- }
- int[] input = new int[inpuot.Length];
- for(int m = 0; m < n; m++){
- input[m] = Int32.Parse(inpuot[m]);
- }
- int[] outputt = rec(input, 0, input.Length-1);
- oautput += outputt[2] + " " + outputt[0] + " " + outputt[1] + "\n";
- }
- Console.WriteLine(oautput);
- }
- public static int[] rec(int[] arr, int l, int r){
- //pos1, pos2, diff, minpos, maxpos
- if(r-l == 0){
- return new int[]{l,l,0,l,l};
- }
- if(r-l <= 1){
- if(arr[r]>arr[l]){
- return new int[]{l,r,arr[l]-arr[r],l, r};
- }
- return new int[]{l,r,arr[l]-arr[r],r, l};
- }
- int[] links = rec(arr, l, l + ((r-l)/2));
- int[] rechts = rec(arr, l + ((r-l)/2) + 1, r);
- int diffL = links[2];
- int diffR = rechts[2];
- int diffB = arr[links[4]] - arr[rechts[3]];
- int min = 0;
- if(arr[links[3]] > arr[rechts[3]]){
- min = rechts[3];
- }
- else{
- min = links[3];
- }
- int max = 0;
- if(arr[links[4]] < arr[rechts[4]]){
- max = rechts[4];
- }
- else{
- max = links[4];
- }
- if(diffL > diffR && diffL > diffB){
- return new int[]{links[0], links[1], links[2], min, max};
- }
- if(diffR > diffL && diffR > diffB){
- return new int[]{rechts[0], rechts[1], rechts[2], min, max};
- }
- return new int[]{links[4], rechts[3], arr[links[4]] - arr[rechts[3]], min, max};
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement