Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- ll f(string s) {
- string k = "";
- s += '-';
- char sgn = '+';
- ll r = 0;
- int n = s.size();
- for (int i = 0; i < n; ++i) {
- if (s[i] != '+' && s[i] != '-') {
- k += s[i];
- continue;
- }
- if (sgn == '+') {
- r += stoll(k);
- } else {
- r -= stoll(k);
- }
- sgn = s[i];
- k = "";
- }
- return r;
- }
- struct pnt{
- ll len, s, id;
- };
- bool cmp(pnt a, pnt b) {
- return a.len > b.len || a.len == b.len && a.s > b.s;
- }
- bool sh = 0;
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- vector <ll> v;
- int n = 0;
- while (1) {
- string s; cin >> s;
- if (s == ".") {
- break;
- }
- n++;
- ll x = f(s);
- v.pb(x);
- }
- vector <pnt> res;
- for (int i = 0; i < n; ++i) {
- ll sum = 0;
- int j = i - 1;
- while (j + 1 < n && sum + v[j + 1] > 0) {
- j++;
- sum += v[j];
- }
- res.push_back({j - i + 1, sum, i});
- }
- sort(res.begin(), res.end(), cmp);
- if (sh) {
- cout << "see\n";
- cout << "v\n";
- cvl(v);
- cout << "res\n";
- for (auto p: res) {
- cout << p.len << ' ' << p.s << ' ' << p.id << "\n";
- }
- }
- cout << res[0].id + 1 << ' ' << res[0].id + res[0].len << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement