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 <cstdio>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;
const int MAX = 10000;
int n;
pi a[100005];
int elem[10005], t[10005];
int main(){
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%d %d",&a[i].first,&a[i].second);
}
sort(a,a+n);
int p = 0;
long long ret = 0;
for (int i=1; i<=MAX; i++) {
int j = p;
while (j < n && a[j].first == i) j++;
while (p < j) {
long long q = 0;
for (int k=a[p].second; k<=MAX; k++) {
q += t[k] * (k - a[p].second);
}
for (int k=a[p].second; k; k--) {
q += t[k] * (a[p].second - k);
}
elem[a[p].second]++;
p++;
ret += q;
}
for (int k=1; k<=MAX; k++) {
t[k] += elem[k];
}
}
printf("%lld",ret);
}
# | 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... |