Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <set>
- #include <stack>
- #include <queue>
- #include <deque>
- using namespace std;
- #define TASK "negcycle"
- string s;
- char minb[200000];
- int nom[200000], mind, maxk, n, idx;
- int main() {
- #ifdef _DEBUG
- freopen("debug.in", "r", stdin);
- freopen("debug.out", "w", stdout);
- #else
- freopen(TASK".in", "r", stdin);
- freopen(TASK".out", "w", stdout);
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- #endif // _DEBUG
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout.precision(6);
- cin >> s;
- n = s.size();
- minb[0] = s[0];
- nom[0] = 0;
- for (int i = 1; i<n; i++)
- {
- if (s[i] <= minb[i - 1])
- {
- minb[i] = s[i];
- nom[i] = i;
- }
- else
- {
- minb[i] = minb[i - 1];
- nom[i] = nom[i - 1];
- }
- }
- maxk = s[n - 1] - minb[n - 1];
- idx = nom[n - 1];
- mind = n - nom[n - 1];
- for (int i = n - 2; i >= 0; i--)
- {
- if (s[i] - minb[i]==maxk && mind > i - nom[i] || s[i] - minb[i] > maxk)
- {
- idx = nom[i];
- mind = i - nom[i] + 1;
- maxk = s[i] - minb[i];
- }
- }
- cout << s.substr(idx, mind);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement