Submission #13857

#TimeUsernameProblemLanguageResultExecution timeMemory
13857gs14004사회적 불평등 (TOKI14_social)C++14
29 / 100
300 ms1944 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...