Submission #832672

# Submission time Handle Problem Language Result Execution time Memory
832672 2023-08-21T13:35:21 Z Jokubas Crosses on the Grid (FXCUP4_cross) C++17
8 / 100
259 ms 26912 KB
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;

using namespace std;

ll SelectCross (int K, vector<int> I, vector<int> O)
{
    ll ats = 0;

    int N = I.size();

    map<int, vector<int>> lol;

    vector<pair<int, int>> visi;
    //int didziausias = 0;
    for(int i = 0; i<N; i++)
    {
        visi.pb({I[i], O[i]});

        lol[I[i]].pb(O[i]);

        //didziausias = max(didziausias, I[i]);
    }

    sort(visi.begin(), visi.end());
    reverse(visi.begin(), visi.end());

    int kiek = lol.size();

    int kur = 0;
    int isviso = 0;

    //vector<int> didziausi;
    deque<int> didziausi;

    for(int i = 0; i<kiek; i++)
    {
        int dabar = visi[kur].first;


        int kiekisI = lol[dabar].size();

        isviso += kiekisI;


        /*if(isviso<K)
        {
            for(int j = 0; j<kiekisI; j++)
            {
                didziausi.pb(visi[j].second);
            }

            for(auto c : lol[dabar])
            {
                didziausi.pb(c);
            }

            kur = isviso;
            continue;
        }*/

        if(didziausi.size() == 0)
        {
            for(int j = 0; j<min(K, kiekisI); j++)
            {
                didziausi.pb(visi[kur + j].second);
            }
        } else
        {
            /*for(int j = 0; j<min(K, kiekisI); j++)
            {
                if(didziausi.size()>0)
                {
                    if(visi[kur + j].second > didziausi[K-1])
                    {
                        didziausi.pb(visi[kur + j].second);
                    }
                } else
                {
                    didziausi.pb(visi[kur + j].second);
                }
            }*/
            int k = 0;
            int j = 0;

            while(j < K && k < kiekisI)
            {
                if(visi[kur + k].second > didziausi[j])
                {
                    didziausi.insert(didziausi.begin() + j, visi[kur + k].second);
                    k++;
                }
                j++;
            }
        }



        /*sort(didziausi.begin(), didziausi.end());
        reverse(didziausi.begin(), didziausi.end());

        if(didziausi.size()>K)
            didziausi.erase(didziausi.begin() + K, didziausi.end());*/


        ll plotas = (ll)dabar*(2*(ll)didziausi[min((int)didziausi.size()-1, K-1)] - (ll)dabar);

        ats = max(ats, plotas);

        kur = isviso;
    }


    return ats;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 7 ms 1876 KB Output is correct
6 Correct 207 ms 26800 KB Output is correct
7 Correct 259 ms 26840 KB Output is correct
8 Correct 216 ms 26912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 7 ms 1876 KB Output is correct
6 Correct 207 ms 26800 KB Output is correct
7 Correct 259 ms 26840 KB Output is correct
8 Correct 216 ms 26912 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 7 ms 1876 KB Output is correct
6 Correct 207 ms 26800 KB Output is correct
7 Correct 259 ms 26840 KB Output is correct
8 Correct 216 ms 26912 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -