# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226338 | Ruxandra985 | Coin Collecting (JOI19_ho_t4) | C++14 | 83 ms | 9212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
pair <long long,long long> v[200010];
long long f[200010][3];
long long modul (long long x){
return max(x , -x);
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
long long i , n , j , under1 , under2 , cnt1 , cnt2 , ic , jc;
long long sol = 0;
fscanf (fin,"%lld",&n);
for (i = 1 ; i <= 2 * n ; i++){
fscanf (fin,"%lld%lld",&v[i].first,&v[i].second);
/// acum reduci v ul
if (v[i].second <= 1){
sol = sol + 1 - v[i].second;
v[i].second = 1;
}
else {
sol = sol + v[i].second - 2;
v[i].second = 2;
}
if (v[i].first < 1){
sol = sol + 1 - v[i].first;
v[i].first = 1;
}
else if (v[i].first > n){
sol = sol + v[i].first - n;
v[i].first = n;
}
f[v[i].first][v[i].second]++;
}
/// renunt la heap gata ok am inteles, nu e bn:)))))
/// ok o sa renunt si la celalalt greedy :(((
ic = 1;
jc = 1;
for (i = 1 ; i <= n ; i++){
for (j = 1 ; j <= f[i][1] + f[i][2] ; j++){
sol = sol + modul(i - ic);
jc++;
if (jc == 3){
jc = 1;
ic++;
}
}
}
under1 = under2 = 0;
cnt1 = cnt2 = 0;
for (i = 1 ; i <= n ; i++){
under1++;
under2++;
cnt1 += f[i][1];
cnt2 += f[i][2];
while (under1 && cnt1){
under1--;
cnt1--;
}
while (under2 && cnt2){
under2--;
cnt2--;
}
while (under1 && cnt2){
under1--;
cnt2--;
sol++;
}
while (under2 && cnt1){
under2--;
cnt1--;
sol++;
}
}
fprintf (fout,"%lld",sol);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |