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 <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <functional>
#include <climits>
using namespace std;
int main()
{
cin.tie(NULL); cout.tie(NULL);
ios_base::sync_with_stdio(false);
int n; cin >> n;
pair<int, int> ar[5005];
for (int i = 0; i < n; i++) cin >> ar[i].first >> ar[i].second;
sort(ar, ar + n);
int ans = 0;
for (int i = 0; i < n; i++)
{
int k = INT_MAX;
for (int j = i - 1; j >= 0; j--)
{
if (ar[j].second == ar[i].second)
{
k = min(k, ar[i].first - ar[j].first);
break;
}
}
for (int j = i + 1; j < n; j++)
{
if (ar[j].second == ar[i].second)
{
k = min(k, ar[j].first - ar[i].first);
break;
}
}
ans += k;
}
cout << ans;
}
# | 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... |