Submission #3437310


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

#define long long long // for codeforces

int main(){
  int n,m,l;
  cin>>n>>m>>l;
  vector<long> d(n);
  rep(i,n) cin>>d[i];

  set<long> go_all;
  vector<set<long>> go_part(n), back_part(n);
  vector<long> times;

  rep(i,m){
    long x,a;
    cin>>x>>a;
    x--;
    go_all.insert(a);
    go_part[x].insert(a);
    times.pb(a);
  }
  rep(i,l){
    long x,a;
    cin>>x>>a;
    x--;
    back_part[x].insert(a);
  }

  vector<pair<long,long>> moves; // closed range
  rep(i,n){
    for(auto s : go_part[i]){
      long arrive = s + d[i];
      auto itr = back_part[i].upper_bound(arrive);
      if(itr == back_part[i].end()) continue;
      long t = *itr + d[i];
      times.pb(s);
      times.pb(t);
      moves.pb({s,t});
    }
  }

  uniq(times);
  uniq(moves);
  const int INF = 123456789;
  vector<int> mv(times.size(), INF);
  for(auto &p : moves) {
    int s = lower_bound(all(times), p.first) - begin(times);
    int t = lower_bound(all(times), p.second) - begin(times);
    mv[s] = min(mv[s], t);
  }

  vector<int> dp(times.size()+1, 0);
  dp[0] = 0;
  rep(i,times.size()){
    if(i>0) dp[i] = max(dp[i-1], dp[i]);
    if(mv[i] < INF) dp[mv[i]+1] = max(dp[mv[i]+1], dp[i] + 2);
  }

  int ans = 0;
  rep(i,times.size()+1){
    ans = max(ans, dp[i]);
    if(i < times.size()){
      long t = times[i];
      if(go_all.lower_bound(t) != end(go_all)) ans = max(ans, dp[i]+1);
    }
  } 

  cout << ans << endl;

  return 0;
}

Submission Info

Submission Time
Task D - Novelist
User SyntaxSato
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2386 Byte
Status AC
Exec Time 258 ms
Memory 28400 KiB

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 30 / 30 470 / 470
Status
AC × 2
AC × 18
AC × 39
Set Name Test Cases
Sample 01_sample_02, 11_sample_01
Subtask 01_sample_02, 02_hand_01, 02_hand_02, 02_hand_03, 02_hand_04, 02_hand_05, 03_random_01, 03_random_02, 03_random_03, 03_random_04, 03_random_05, 03_random_06, 03_random_07, 03_random_08, 03_random_09, 03_random_10, 03_random_11, 03_random_12
All 01_sample_02, 02_hand_01, 02_hand_02, 02_hand_03, 02_hand_04, 02_hand_05, 03_random_01, 03_random_02, 03_random_03, 03_random_04, 03_random_05, 03_random_06, 03_random_07, 03_random_08, 03_random_09, 03_random_10, 03_random_11, 03_random_12, 11_sample_01, 12_hand_01, 12_hand_02, 12_hand_03, 12_hand_04, 12_hand_05, 13_random_01, 13_random_02, 13_random_03, 13_random_04, 13_random_05, 13_random_06, 13_random_07, 13_random_08, 13_random_09, 13_random_10, 13_random_11, 13_random_12, 14_MAX_N_01, 14_MAX_N_02, 14_MAX_N_03
Case Name Status Exec Time Memory
01_sample_02 AC 1 ms 256 KiB
02_hand_01 AC 1 ms 256 KiB
02_hand_02 AC 1 ms 256 KiB
02_hand_03 AC 1 ms 256 KiB
02_hand_04 AC 1 ms 256 KiB
02_hand_05 AC 1 ms 256 KiB
03_random_01 AC 219 ms 16880 KiB
03_random_02 AC 161 ms 13680 KiB
03_random_03 AC 254 ms 20208 KiB
03_random_04 AC 234 ms 20080 KiB
03_random_05 AC 233 ms 16880 KiB
03_random_06 AC 232 ms 18416 KiB
03_random_07 AC 221 ms 18928 KiB
03_random_08 AC 195 ms 15600 KiB
03_random_09 AC 225 ms 18928 KiB
03_random_10 AC 223 ms 20080 KiB
03_random_11 AC 127 ms 10740 KiB
03_random_12 AC 131 ms 11120 KiB
11_sample_01 AC 1 ms 256 KiB
12_hand_01 AC 1 ms 256 KiB
12_hand_02 AC 1 ms 256 KiB
12_hand_03 AC 1 ms 256 KiB
12_hand_04 AC 1 ms 256 KiB
12_hand_05 AC 1 ms 256 KiB
13_random_01 AC 224 ms 22896 KiB
13_random_02 AC 193 ms 19292 KiB
13_random_03 AC 144 ms 16500 KiB
13_random_04 AC 244 ms 20464 KiB
13_random_05 AC 182 ms 14448 KiB
13_random_06 AC 211 ms 15856 KiB
13_random_07 AC 220 ms 15856 KiB
13_random_08 AC 173 ms 11764 KiB
13_random_09 AC 258 ms 19568 KiB
13_random_10 AC 146 ms 11504 KiB
13_random_11 AC 174 ms 13424 KiB
13_random_12 AC 126 ms 10356 KiB
14_MAX_N_01 AC 247 ms 25972 KiB
14_MAX_N_02 AC 257 ms 28400 KiB
14_MAX_N_03 AC 227 ms 28144 KiB