Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×
Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

Блог пользователя anushkanocoding

Автор anushkanocoding, история, 8 часов назад, По-английски

heres the link for the question "Divan and a new Project" [](https://codeforces.me/contest/1614/problem/B)

Why wont this solution work? It prints the correct minimum time taken and also prints the coordinates properly. But when i submit it shows error on the first testcase and says — "wrong answer answer is wrong: pans = 14 is not equal real_pans = 18 (test case 1)" i dont get this. the answer to the first example is 14 why is it saying its 18?

import java.util.*;
public class divan {
    public static void main(String[]args){
        java.util.Scanner sc=new java.util.Scanner(System.in);
        int t=sc.nextInt();
        
        for(int i=0;i<t;i++){
            int n=sc.nextInt();
            int []arr=new int[n];

            for(int j=0;j<n;j++)arr[j]=sc.nextInt();

            Arrays.sort(arr);

            
            boolean negative=true;
            int neg=-1;
            int pos=1;
            boolean positive=false;
            int time=0;
            int []ans=new int[n+1];
            ans[0]=0;
            int idx=1;
            for(int j=n-1;j>=0;j--){
                if(negative){
                    int now=2*Math.abs(0-neg)*arr[j];
                    ans[idx]=neg;
                    idx++;
                    time+=now;
                    positive=true;
                    negative=false;
                }
                else{
                    int now=2*Math.abs(0-pos)*arr[j];
                    ans[idx]=pos;
                    idx++;
                    time+=now;
                    positive=false;
                    negative=true;
                    neg--;
                    pos++;
                }
            }
            System.out.println(time);
            for(int j=0;j<ans.length;j++)System.out.print(ans[j] + " ");
            System.out.println();
        }
        sc.close();
    }
}
  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
7 часов назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

The problem is in the order of ans. ans[0] should contain the coordinate for the headquarters (this part you're doing right), but ans[1] should contain the coordinate of the 0-th building, ans[2] should contain the coordinate for the 1-st building, and so on up to ans[n].

  • »
    »
    7 часов назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    thank you so much i got it now!