package P0;

import D1.F;
import java.util.ArrayList;
import java.util.Collections;

/* JADX INFO: loaded from: classes.dex */
public final class q {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final F f5316g = new F(11);

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final F f5317h = new F(12);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f5321d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f5322e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f5323f;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final p[] f5319b = new p[5];

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ArrayList f5318a = new ArrayList();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f5320c = -1;

    public final void a(int i, float f3) {
        p pVar;
        int i5 = this.f5320c;
        ArrayList arrayList = this.f5318a;
        if (i5 != 1) {
            Collections.sort(arrayList, f5316g);
            this.f5320c = 1;
        }
        int i8 = this.f5323f;
        p[] pVarArr = this.f5319b;
        if (i8 > 0) {
            int i9 = i8 - 1;
            this.f5323f = i9;
            pVar = pVarArr[i9];
        } else {
            pVar = new p();
        }
        int i10 = this.f5321d;
        this.f5321d = i10 + 1;
        pVar.f5313a = i10;
        pVar.f5314b = i;
        pVar.f5315c = f3;
        arrayList.add(pVar);
        this.f5322e += i;
        while (true) {
            int i11 = this.f5322e;
            if (i11 <= 2000) {
                return;
            }
            int i12 = i11 - 2000;
            p pVar2 = (p) arrayList.get(0);
            int i13 = pVar2.f5314b;
            if (i13 <= i12) {
                this.f5322e -= i13;
                arrayList.remove(0);
                int i14 = this.f5323f;
                if (i14 < 5) {
                    this.f5323f = i14 + 1;
                    pVarArr[i14] = pVar2;
                }
            } else {
                pVar2.f5314b = i13 - i12;
                this.f5322e -= i12;
            }
        }
    }

    public final float b() {
        int i = this.f5320c;
        ArrayList arrayList = this.f5318a;
        if (i != 0) {
            Collections.sort(arrayList, f5317h);
            this.f5320c = 0;
        }
        float f3 = 0.5f * this.f5322e;
        int i5 = 0;
        for (int i8 = 0; i8 < arrayList.size(); i8++) {
            p pVar = (p) arrayList.get(i8);
            i5 += pVar.f5314b;
            if (i5 >= f3) {
                return pVar.f5315c;
            }
        }
        if (arrayList.isEmpty()) {
            return Float.NaN;
        }
        return ((p) arrayList.get(arrayList.size() - 1)).f5315c;
    }
}
