# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
931702 | Yazan_Alattar | Advertisement 2 (JOI23_ho_t2) | C++14 | 524 ms | 74816 KiB |
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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 1000007;
const ll inf = 1e9;
const ll INF = 1e12;
const ll mod = 1e9 + 7;
const double eps = 1e-6;
pair <ll,ll> a[M];
vector <ll> adj[M];
vector < pair <ll,ll> > order;
priority_queue < pair <ll,ll> > q;
ll n, ans;
bool visit[M], done[M];
void solve(int _){
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> a[i].F >> a[i].S;
order.pb({a[i].F, i});
q.push({a[i].S, i});
}
sort(all(order));
for(int i = 0; i < order.size(); ++i){
if(i > 0) adj[order[i].S].pb(order[i - 1].S);
if(i + 1 < order.size()) adj[order[i].S].pb(order[i + 1].S);
}
while(!q.empty()){
int i = q.top().S;
int cost = q.top().F;
q.pop();
if(done[i]) continue;
done[i] = 1;
if(!visit[i]) ++ans;
for(auto j : adj[i]){
int newCost = a[i].S - abs(a[i].F - a[j].F);
if(newCost >= a[j].S) visit[j] = 1;
if(newCost > a[j].S){
a[j].S = newCost;
q.push({newCost, j});
}
}
}
cout << ans << endl;
return;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; ++i) solve(t);
return 0;
}
Compilation message (stderr)
# | 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... |