Submission #1772972
Source Code Expand
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {
os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T,class U> ostream& operator<<(ostream &os, const tuple<S,T,U> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class S, class T,class U,class V> ostream& operator<<(ostream &os, const tuple<S,T,U,V> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<","<<get<3>(t)<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#undef _DEBUG
#ifdef _DEBUG
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
#else
#define out
#endif
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
const ll MOD=1e9+7;
const int nnn=112345;
ll bit[nnn+1];
ll minf(int i){++i; //閉区間
ll s=0;
while(i>0){
s=max(s,bit[i]);
i-=i&-i;
}return s;
}
void upd(int i,ll val){++i; //より小さいのに更新される場合のみ
while(i<=nnn){
bit[i]=max(bit[i],val);
i+=i&-i;
}
return;
}
const int MAX_N=(1<<18);
int nn=MAX_N;
struct Seg{
int mn,ind;
Seg(int d=1000000,int i=100000){
mn=d;
ind=i;
}
static Seg e;
};
vector<Seg> dat(2*MAX_N);
Seg Seg::e=Seg();
Seg operator+(Seg l,Seg r){
if(l.mn>r.mn)
swap(l,r);
return l;
}
//ostream& operator<<(ostream &os, const Seg &t) { return os<<"["<<t.mn<<")";}
template<class T=Seg> void upd(int k,T a,vector<T> &dat=dat){
k+=dat.size()/2-1;
dat[k]=a;
while(k>0){
k=(k-1)/2;
dat[k]=dat[k*2+1]+dat[k*2+2];
}
}
//(l,r,0,0,nn)
template<class T=Seg> T query(int a,int b,const vector<T> &dat=dat,int k=0,int l=0,int r=-1){
if(r<0) r=dat.size()/2;
if(r<=a || b<=l)return T::e;
if(a<=l && r<=b) return dat[k];
T lv=query(a,b,dat,k*2+1,l,(l+r)/2) ,rv= query(a,b,dat,k*2+2,(l+r)/2,r);
return lv+rv;
}
int dp[112345];
int main(){
ios_base::sync_with_stdio(false);
cout<<fixed<<setprecision(0);
int n,m;
cin>>n>>m;
vector<pii> ps(n);
rep(i,n){
int a,b;
cin>>a>>b;
++a;
ps[i]=pii(a,a+b);
}
iota(dp,dp+112345,0);
sort(all(ps),[](pii p,pii q){return p.Y<q.Y;});
for(pii p:ps){
out(p,1);
//rep(i,10) cout<<query(i,i+1).mn<<",";cout<<endl;
MN<int>(dp[p.Y],p.X-minf(p.X));
out(p.X-minf(p.X-1),1);
MN<int>(dp[p.Y],query(p.X+1,p.Y+1).mn-p.X);
out(query(p.X+1,p.Y+1).mn-p.X,1);
out(dp[p.Y],p.Y,1);
upd(p.Y,ll(p.Y-dp[p.Y]));
upd(p.Y,Seg(dp[p.Y]+p.Y));
//rep(i,20) cout<<dp[i]<<",";cout<<endl;
}
int re=0;
for(pii p:ps) MX(re,p.Y-dp[p.Y]);
cout<<re<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
H - 焼肉の達人 |
User |
nuip |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
4822 Byte |
Status |
AC |
Exec Time |
111 ms |
Memory |
6400 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt |
All |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
3 ms |
4864 KB |
01-02.txt |
AC |
61 ms |
5632 KB |
01-03.txt |
AC |
3 ms |
4864 KB |
01-04.txt |
AC |
64 ms |
5632 KB |
01-05.txt |
AC |
72 ms |
5632 KB |
01-06.txt |
AC |
84 ms |
5632 KB |
01-07.txt |
AC |
64 ms |
5632 KB |
01-08.txt |
AC |
67 ms |
5632 KB |
01-09.txt |
AC |
70 ms |
5632 KB |
01-10.txt |
AC |
3 ms |
4864 KB |
01-11.txt |
AC |
3 ms |
4736 KB |
01-12.txt |
AC |
3 ms |
4864 KB |
01-13.txt |
AC |
3 ms |
5248 KB |
01-14.txt |
AC |
6 ms |
5632 KB |
01-15.txt |
AC |
110 ms |
6400 KB |
01-16.txt |
AC |
111 ms |
6400 KB |
01-17.txt |
AC |
111 ms |
6400 KB |
01-18.txt |
AC |
111 ms |
6400 KB |
01-19.txt |
AC |
75 ms |
6400 KB |
01-20.txt |
AC |
76 ms |
6400 KB |
01-21.txt |
AC |
79 ms |
6400 KB |
01-22.txt |
AC |
80 ms |
6400 KB |
01-23.txt |
AC |
81 ms |
6400 KB |
01-24.txt |
AC |
82 ms |
6400 KB |
01-25.txt |
AC |
83 ms |
6400 KB |
01-26.txt |
AC |
85 ms |
6400 KB |
01-27.txt |
AC |
88 ms |
6400 KB |
01-28.txt |
AC |
94 ms |
6400 KB |
01-29.txt |
AC |
96 ms |
6400 KB |
01-30.txt |
AC |
100 ms |
6400 KB |
01-31.txt |
AC |
3 ms |
5248 KB |
01-32.txt |
AC |
4 ms |
5632 KB |
01-33.txt |
AC |
3 ms |
4864 KB |
01-34.txt |
AC |
4 ms |
5632 KB |
01-35.txt |
AC |
12 ms |
5632 KB |
01-36.txt |
AC |
4 ms |
5632 KB |
01-37.txt |
AC |
3 ms |
5248 KB |
01-38.txt |
AC |
12 ms |
5632 KB |
01-39.txt |
AC |
4 ms |
5632 KB |
01-40.txt |
AC |
5 ms |
5632 KB |
01-41.txt |
AC |
74 ms |
6400 KB |
01-42.txt |
AC |
73 ms |
6400 KB |
01-43.txt |
AC |
73 ms |
6400 KB |
01-44.txt |
AC |
73 ms |
6400 KB |
01-45.txt |
AC |
86 ms |
5632 KB |
01-46.txt |
AC |
111 ms |
6400 KB |
01-47.txt |
AC |
75 ms |
6400 KB |
01-48.txt |
AC |
84 ms |
6400 KB |
01-49.txt |
AC |
99 ms |
6400 KB |
sample-01.txt |
AC |
3 ms |
4864 KB |
sample-02.txt |
AC |
3 ms |
4864 KB |