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>
#define suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
void solve(){
ll n;
cin>>n;
ll l[n+5],r[n+5],took[n+5]={};
vector<pair<ll,ll>>v;
for(ll i=1;i<=n;i++){
cin>>l[i]>>r[i];
l[i]=min(i-1,l[i]);
r[i]=min(n-i,r[i]);
v.push_back({l[i]+r[i],i});
}
sort(v.begin(),v.end());
ll ans=0;
for(auto ss:v){
auto [val,idx]=ss;
bool fla=0;
for(int i=idx-l[idx];i<=idx+r[idx];i++) fla|=took[i];
if(fla) continue;
took[idx]=1;
ans++;
}
co ans;
}
int main()
{
suiii
int _=1;
// cin>>_;
while(_--) solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:25:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
25 | auto [val,idx]=ss;
| ^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |