Save the Queen!

Sort by

recency

|

38 Discussions

|

  • + 0 comments

    only 13 testcases are passed out of 23 testcases!!

  • + 0 comments

    This is my solution in C++:

    #include <cstdio>
    #include <algorithm>
    
    int main(){
    	int n, k;
    	FILE* fin = fopen("save.txt", "rt");
    	fin = stdin;
    	
    	fscanf(fin, "%d %d\n", &n, &k);
    	
    	long double times[k];
    	
    	for(long long i = 0; i < k; i++){
    		fscanf(fin, "%Lf", &times[i]);
    	}
    	
    	std::sort(times, times + k);
    	
    	long long d1;
    	long long i = 0; long long j;
    	long double dif; long double a;
    	long long d = 1;
    	i = k - n;
    	
    	j = i-1;
    	while(j >= 0 && times[j] == times[i]){
    		d++;
    		j--;
    		if(i > 0) i--;
    	}
    	j = k - n + 1;
    	while(j < k && times[j] == times[i]){
    		d++;
    		j++;
    	}
    	long double total = 0;
    	while(times[k - n] >= 0.0000000001){
    		if(i > 0){
    			dif = times[i] - times[i - 1];
    			j = i - 1;
    			while(j >= 0 && times[j] == times[i]){
    				d++;
    				j--;
    				if(i > 0) i--;
    			}
    		}
    		else{
    			dif = times[0];
    			i = 0;
    		}
    		
    		d1 = i + d - k + n;
    
    		if(d > d1 && d < k - 1) a = (times[i+d] - times[i])*d1/(d-d1);
    		else a = dif+1;
    
    		if(!(a < dif)) a = dif;
    		total += a*d/d1;
    		for(j = i; j <= i+d-1; j++){
    			times[j] -= a;
    		}
    		for(j = i+d; j < k; j++){
    			times[j] -= a*d/d1;
    		}
    		
    		j = i+d;
    		while(j < k && times[j] == times[i]){
    			d++;
    			j++;
    		}
    	}
    
    	printf("%.9Lf\n", total);
    	
    	return 0;
    }
    
  • + 0 comments

    Thank you!

  • + 0 comments

    the editorial is so hard.Look at it once.

    def solve(n, a):
        a=sorted(a,reverse=True);
        reallis=a[:n];
        sum1=sum(a[n:]);
        #print(reallis,sum1)
        reallis=sorted(reallis);
        temp=0;
        sum2=0;
        no=0;
        f=0;
        for i in range(len(reallis)):
            no+=1;
            sum2+=reallis[i];
            temp=round((sum1+sum2),9)/no;
            #print(temp);
            if(i<(len(reallis)-1)):
                if(temp<=reallis[i+1]):
                    f=1;
                    print("{0:.9f}".format(temp));
    
                break;
            else:
                continue;
    if(f==0):
        print("{0:.9f}".format(temp));
    
  • + 1 comment

    public static void solve(int n, List a) {

        Collections.sort(a);
        double sum = 0;
        for(int an : a){
            sum+= an;
        }
        int k = a.size();
        double ans = a.get(0);
         for(int i = k - 1; i >= 0; i --) {
            if(sum / (n - (k - 1 - i)) > a.get(i)) {
                ans = sum / (n - (k - 1 - i));
                break;
            }
            sum -= a.get(i);
        }
        System.out.println(ans);
    
    }