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 <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
const int M=1e5+100;
int cnt[M];
long long mx=1e18,ans=0;
int n;
vector<pair<int,int>> a;
long long f(long long x)
{
return (x*(x+1))/2;
}
void recur(int x);
void place(int curh,int mxh,int curpl,int pl,int x)
{
if(curpl==pl)
{
recur(x+1);
return;
}
if(curh==mxh)
{
return;
}
ans+=cnt[curh];
cnt[curh]++;
place(curh+1,mxh,curpl+1,pl,x);
cnt[curh]--;
ans-=cnt[curh];
place(curh+1,mxh,curpl,pl,x);
}
void recur(int x)
{
if(ans>=mx)
{
return;
}
if(x==n)
{
mx=min(mx,ans);
return;
}
place(0,a[x].first,0,a[x].second,x);
}
signed main()
{
cin>>n;
for(int i=0;i<n;i++)
{
int h,k;
cin>>h>>k;
a.push_back({h,k});
}
recur(0);
cout<<mx<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |