이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define F first
#define S second
#define MAX 500005
#define oo 1e18
#define mod 1000000007
#define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
using namespace std;
typedef long long ll;
#define pll pair<ll , ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vpll vector<pll>
ll pass[MAX],n;
pll a[MAX];
int main(){
fast_in
cin>>n;priority_queue<pair<pll,ll>> q;
for(int i=0;i<n;i++){
cin>>a[i].F>>a[i].S;
}sort(a,a+n);
for(int i=0;i<n;i++)
q.push({{a[i].S,(ll)-1},i});
ll r=0;
while(!q.empty()){
pair<pll,ll> u=q.top();q.pop();
//cout<<u.S<<" "<<u.F.F<<"\n";
if(pass[u.S]==1)continue;
pass[u.S]=1;r-=u.F.S;
if(u.S>0) q.push({{u.F.F-abs(a[u.S].F-a[u.S-1].F),(ll)0},u.S-1});
if(u.S<n-1) q.push({{u.F.F-abs(a[u.S].F-a[u.S+1].F),(ll)0},u.S+1});
}
cout<<r;
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... |