117982024-11-11 12:48:28Leventusz09Forma-1cpp17Wrong answer 0/1002.091s836 KiB
#include <bits/stdc++.h>

using namespace std;

int partition(vector<pair<int, long long>> &vec, int low, int high) {

    // Selecting last element as the pivot
    pair<int, long long> pivot = vec[high];

    // Index of elemment just before the last element
    // It is used for swapping
    int i = (low - 1);

    for (int j = low; j <= high - 1; j++) {

        // If current element is smaller than or
        // equal to pivot
        if (vec[j].second <= pivot.second) {
            i++;
            swap(vec[i], vec[j]);
        }
    }

    // Put pivot to its position
    swap(vec[i + 1], vec[high]);

    // Return the point of partition
    return (i + 1);
}

void quickSort(vector<pair<int, long long>> &vec, int low, int high) {

    // Base case: This part will be executed till the starting
    // index low is lesser than the ending index high
    if (low < high) {

        // pi is Partitioning Index, arr[p] is now at
        // right place
        int pi = partition(vec, low, high);

        // Separately sort elements before and after the
        // Partition Index pi
        quickSort(vec, low, pi - 1);
        quickSort(vec, pi + 1, high);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N;
    cin >> N;

    vector<long long> a(N), b(N), c(N);

    for(int i=0; i<N; i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    int Q;
    cin >> Q;

    for(int i=0, j; i<Q; i++){
        int Pi;
        long long Ti;
        cin >> Pi >> Ti;
        vector<pair<int, long long>> dist(N);
        for(j=0; j<N; j++){
            dist[j].first = j;
            dist[j].second = a[j] * Ti * Ti + b[j] * Ti + c[j];
        }

        quickSort(dist, 0, dist.size()-1);

        /*sort(dist.begin(), dist.end(), [](pair<int, long long> a, pair<int, long long> b){
            return a.second > b.second;
        });*/

        cout << dist[Pi-1].first+1 << "\n";


    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms320 KiB
subtask20/20
2Wrong answer76ms740 KiB
3Wrong answer81ms756 KiB
4Wrong answer76ms824 KiB
5Wrong answer81ms760 KiB
6Wrong answer85ms836 KiB
7Wrong answer79ms824 KiB
8Wrong answer79ms744 KiB
9Wrong answer79ms752 KiB
subtask30/30
10Time limit exceeded2.091s556 KiB
11Wrong answer1.521s504 KiB
12Time limit exceeded2.091s572 KiB
13Time limit exceeded2.091s508 KiB
14Time limit exceeded2.073s320 KiB
15Time limit exceeded2.075s508 KiB
16Time limit exceeded2.075s320 KiB
17Time limit exceeded2.073s568 KiB
18Time limit exceeded2.085s556 KiB
subtask40/50
19Time limit exceeded2.084s320 KiB
20Time limit exceeded2.084s508 KiB
21Time limit exceeded2.084s504 KiB
22Time limit exceeded2.084s536 KiB
23Time limit exceeded2.084s560 KiB
24Time limit exceeded2.084s320 KiB
25Time limit exceeded2.082s568 KiB
26Time limit exceeded2.084s568 KiB
27Time limit exceeded2.081s504 KiB
28Time limit exceeded2.078s692 KiB
29Time limit exceeded2.082s548 KiB
30Time limit exceeded2.079s320 KiB