#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;
for(int i = 0; i<kiek; i++)
{
int dabar = visi[kur].first;
int kiekisI = lol[dabar].size();
isviso += kiekisI;
if(isviso<K)
{
for(auto c : lol[dabar])
{
didziausi.pb(c);
}
kur = isviso;
continue;
}
for(int j = 0; j<min(K, kiekisI); j++)
{
didziausi.pb(visi[kur + j].second);
}
sort(didziausi.begin(), didziausi.end());
reverse(didziausi.begin(), didziausi.end());
didziausi.erase(didziausi.begin() + K, didziausi.end());
ll plotas = dabar*(2*didziausi[K-1] - dabar);
ats = max(ats, plotas);
kur = isviso;
}
return ats;
}
/*void setIO(string s)
{
freopen((s+".in").c_str(), "r", stdin);
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(nullptr);
//setIO("input");
int N, K;
//int I[N];
//int O[N];
vector<int> I;
vector<int> O;
cin>>N>>K;
for(int i = 0; i<N; i++)
{
//cin>>I[i]>>O[i];
int a, b;
cin>>a>>b;
I.pb(a);
O.pb(b);
}
cout<<SelectCross(K, I, O);
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |