Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstdio>
- #include <iomanip>
- #include <vector>
- #include <set>
- #include <map>
- #include <algorithm>
- #include <cmath>
- #include <sstream>
- #include <string>
- #include <memory.h>
- using namespace std;
- void prepare()
- {
- #ifdef _DEBUG
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- #endif
- cin.sync_with_stdio(false);
- cout.sync_with_stdio(false);
- }
- const int MAXINT = 200001;
- int t[MAXINT + 1], MAX[MAXINT + 1], n;
- void rec(int i, int value)
- {
- MAX[i] = value;
- if (t[i] > 0 && i + t[i] <= MAXINT && MAX[i + t[i]] <= value)
- rec(i + t[i], value + 1);
- }
- int main()
- {
- prepare();
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- int t1, td;
- cin >> t1 >> td;
- t[t1] = max(td, t[t1]);
- }
- for (int i = 0; i < MAXINT + 1; i++)
- {
- MAX[i] = -1;
- }
- //memset(MAX, 255, MAXINT + 1);
- MAX[0] = 0;
- for (int i = 1; i < MAXINT + 1 ; i++)
- {
- MAX[i] = max(MAX[i], MAX[i - 1]);
- if (t[i] > 0 && i + t[i] <= MAXINT && MAX[i + t[i]] <= MAX[i])
- rec(i + t[i], MAX[i] + 1);
- }
- cout << MAX[MAXINT];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement