text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string s; cin >> s; int sp = -1; for (int i = 0; i < s.length() - 1; i++) { if (s[i] > s[i + 1]) { sp = i + 1; } } if (sp == -1) { cout << "NO" << endl; } else cout << "YES" << endl << sp << " " << sp + 1 << endl; }
#include <bits/stdc++.h> using namespace std; const long double E = 2.71828182845904523536; const long double pi = acos(-1); const double eps = 1e-9; const long long mod = 1e9 + 7; const long long inf = 1LL << 30; const int N = 300300; char a[N]; int main() { int n; scanf("%d", &n); scanf("%s", &a); for (int i = 0; i < n - 1; i++) { if (a[i + 1] < a[i]) { printf("YES\n"); printf("%d %d\n", i + 1, i + 2); return 0; } } printf("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; string str; cin >> str; for (long long i = 1; i < n; i++) { if (str[i] < str[i - 1]) { cout << "YES\n"; cout << i << " " << i + 1 << "\n"; return 0; } } cout << "NO\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; bool flag = false; int ans; for (int i = 1; i < n; i++) { if (s[i] < s[i - 1]) { flag = true; ans = i; break; } } if (flag == false) cout << "NO"; else { cout << "YES" << endl; cout << (ans) << " " << ans + 1; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; string s; cin >> s; int a[n]; for (i = 0; i < n; i++) { a[i] = s[i] - 'a'; } for (i = 0; i < n; i++) { if (a[i] > a[i + 1]) { cout << "YES" << endl; cout << i + 1 << " " << i + 2; return 0; } } cout << "NO"; }
#include <bits/stdc++.h> using namespace std; const int N = 105001; const int SQRTN = 320; const int LOGN = 20; const long double PI = acos(-1); const long double TAU = 2 * PI; string s, x; signed main() { int aaa; cin >> aaa; cin >> s; x = s; sort(x.begin(), x.end()); if (s == x) return puts("NO"); puts("YES"); int n; n = s.size(); for (int i = 1; i < n; i++) { if (s[i] < s[i - 1]) { return printf("%d %d", i, i + 1), 0; } } }
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; string s; cin >> s; for (long long i = 1; i < n; i++) { if (s[i] < s[i - 1]) { cout << "YES" << '\n'; cout << i << " " << i + 1; return; } } cout << "NO"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long int inf = 1000000000; const long long int mod = 1000000000 + 7; inline void IO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); } template <class T> inline int CHECK(T MASK, int i) { return (MASK >> i) & 1; } template <class T> inline T ON(T MASK, int i) { return MASK | (T(1) << i); } template <class T> inline T OFF(T MASK, int i) { return MASK & (~(T(1) << i)); } template <typename T> inline int CNT(T MASK) { if (numeric_limits<T>::digits <= numeric_limits<unsigned int>::digits) return __builtin_popcount(MASK); else return __builtin_popcountll(MASK); } template <class T> inline int RIGHT(T MASK) { return log2(MASK & -MASK); } int dx4[] = {0, 0, -1, +1}; int dy4[] = {+1, -1, 0, 0}; int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0}; int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0}; inline void I(int& a) { scanf("%d", &a); } inline void I(long long int& a) { scanf("%I64d", &a); } inline void I(unsigned long long int& a) { scanf("%I64u", &a); } inline void I(char* a) { scanf("%s", a); } char Iarr[2000010]; inline void I(string& a) { scanf("%s", Iarr); a = Iarr; } template <typename T, typename... Args> void I(T& a, Args&... args) { I(a); I(args...); } inline void OUT(int a) { printf("%d", a); } inline void OUT(long long int a) { printf("%I64d", a); } inline void OUT(const char* a) { printf("%s", a); } inline void OUT(char* a) { printf("%s", a); } inline void OUT(bool a) { printf("%d", a); } inline void OUT(string a) { for (__typeof(a.end()) it = (a.begin()) - ((a.begin()) > (a.end())); it != (a.end()) - ((a.begin()) > (a.end())); it += 1 - 2 * ((a.begin()) > (a.end()))) printf("%c", *it); } inline void OUT(unsigned long long int a) { printf("%I64u", a); } template <typename T, typename... Args> void OUT(T a, Args... args) { OUT(a); OUT(" "); OUT(args...); } template <typename... Args> void O(Args... args) { OUT(args...); OUT("\n"); } template <typename T1, typename T2> inline ostream& operator<<(ostream& os, pair<T1, T2> p) { os << "{" << p.first << ", " << p.second << "}"; return os; } template <typename T> inline ostream& operator<<(ostream& os, vector<T>& a) { os << "["; for (int i = 0; i < (int)a.size(); i++) { if (i) os << ", "; os << a[i]; } os << "]"; return os; } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } const int M = 200010; int main() { int n; string s; I(n, s); char c[n + 1]; int in[n + 1]; char maxx = 'z' + 1; int mi; for (int i = n - 1; i >= 0; i--) { c[i] = maxx; in[i] = mi; if (s[i] < maxx) { maxx = s[i]; mi = i; } } for (int i = 0; i < n; i++) { if (s[i] > c[i]) { O("YES"); O(i + 1, in[i] + 1); exit(0); } } O("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; const char IO_MODE = 0; inline long long ReadInt() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline void WriteInt(long long x) { char CH[20]; if (x < 0) putchar('-'); x = -x; int Num = 0; if (!x) { putchar('0'); return; } while (x > 0) CH[++Num] = x % 10, x /= 10; while (Num) putchar(CH[Num--] + 48); } inline void out(int x) { if (IO_MODE & 1) WriteInt(x); else printf("%i", x); } template <typename... Args> inline void out(int x, Args... args) { out(x); putc(' ', stdout); out(args...); } inline void in(int &x) { if (IO_MODE & 2) x = ReadInt(); else scanf("%i", &x); } template <typename... Args> inline void in(int &x, Args &...args) { in(x); in(args...); } inline void outll(long long x) { if (IO_MODE & 1) WriteInt(x); else printf("%I64d", x); } template <typename... Args> inline void outll(long long x, Args... args) { outll(x); putc(' ', stdout); outll(args...); } inline void inll(long long &x) { if (IO_MODE & 2) x = ReadInt(); else scanf("%I64d", &x); } template <typename... Args> inline void inll(long long &x, Args &...args) { inll(x); inll(args...); } int aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, mm, nn, oo, pp, qq, rr, ss, tt, uu, vv, ww, xx, yy, zz; int tc; int n, occ[33]; string s; int main() { cin >> n >> s; for (int i = 0; i < n; i++) { int x = s[i] - 'a'; for (int j = 26; j > x; j--) { if (occ[j]) { printf("YES"), putc('\n', stdout); cout << occ[j] << " " << i + 1 << endl; return 0; } } occ[x] = i + 1; } printf("NO"), putc('\n', stdout); }
#include <bits/stdc++.h> char s[300001]; using namespace std; int main() { int n, k = 0, p, r; cin >> n; for (int i = 1; i <= n; i++) { cin >> s[i]; } for (int i = 2; i <= n; i++) { if (s[i] - '0' < s[i - 1] - '0') { cout << "YES" << endl; cout << i - 1 << " " << i; break; } else k++; } if (k == n - 1) { cout << "NO"; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 0; cin >> n; string s; cin >> s; for (int i = 1; i < s.size(); i++) { if (s[i] < s[i - 1]) { cout << "YES" << endl; cout << i << " " << i + 1 << endl; m++; i = s.size(); } } if (m == 0) cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; const int md = (int)1e9 + 7; const int siz = 300005; long long arr[siz]; long long n, m, k, l; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; cin >> s; map<char, int> m, mi; for (int i = n - 1; i >= 0; i--) { if (!m[s[i]]) { m[s[i]] = i + 1; } if (!mi[s[i]] || mi[s[i]] > i + 1) { mi[s[i]] = i + 1; } } int sm = 0; for (auto xx : m) { int x1 = xx.first, x = xx.second; for (auto yy : mi) { int y1 = yy.first, y = yy.second; if (y1 > x1 && y < x) { cout << "YES" << '\n' << y << " " << x; return 0; } } } cout << "NO"; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { long long int n; cin >> n; string s; cin >> s; bool fl = 0; int idxl = 0, idxr = 0; for (int i = 1; i < n; i++) { if (s[i] < s[i - 1]) { fl = true; idxl = i; idxr = i + 1; break; } } if (fl == 1) { cout << "YES\n"; cout << idxl << " " << idxr << "\n"; } else cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; int a, b, temp; bool flag = true; for (int i = 0; i < n - 1; i++) { if (flag) { if (str[i + 1] < str[i]) { flag = false; a = (i + 1); } } } if (flag) cout << "NO"; else { cout << "YES" << endl; cout << a << " " << a + 1; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int n; char S[maxn]; int main() { scanf("%d%s", &n, S + 1); for (int i = 1; i < n; i++) if (S[i] > S[i + 1]) { printf("YES\n%d %d\n", i, i + 1); return 0; } puts("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int check = 0; for (int i = 0; i < s.size(); i++) { string s1 = s.substr(i, 2); string s2 = s1; reverse(s1.begin(), s1.end()); if (s1 < s2) { cout << "YES" << endl; cout << i + 1 << " " << i + 2 << endl; return 0; } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; char in[300005]; int main() { int n; cin >> n; scanf("%s", in); int f = 0; for (int i = 1; i < n; i++) { if (in[i] < in[i - 1]) { f = 1; cout << "YES" << endl; cout << i << " " << i + 1 << endl; break; } } if (!f) { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; string s; cin >> n >> s; for (int i = 0; i < (int)s.size() - 1; i++) { if (s[i] > s[i + 1]) { cout << "YES\n"; cout << i + 1 << " " << i + 2; return 0; } } cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; string s; int n; bool b = true; int i = 0; int ans; int main() { cin >> n; cin >> s; while (b && i < n - 1) { if (int(s[i]) > int(s[i + 1])) { b = false; ans = i + 1; } i++; } if (!b) { cout << "YES" << endl; cout << ans << " " << ans + 1; } else { cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; string a = s; sort(a.begin(), a.end()); for (int i = 1; i < n; i++) { if (s[i] < s[i - 1]) { cout << "YES\n" << i << " " << i + 1 << '\n'; return 0; } } cout << "NO\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { puts("YES"); printf("%d %d\n", i + 1, i + 2); return 0; } } puts("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = (int)2e5 + 100; const int INF = 0x3f3f3f3f; int main() { int n; cin >> n; string s; cin >> s; int l = 0, r = 0; char maxx = 'a'; for (int i = (0); i <= (n - 1); ++i) { if (s[i] > maxx) maxx = s[i], l = i; if (s[i] < maxx) { r = i; break; } } if (r == 0) puts("NO"); else { puts("YES"); printf("%d %d\n", l + 1, r + 1); } }
#include <bits/stdc++.h> using namespace std; bool Compare(const pair<int, int> &a, const pair<int, int> &b) { return a.first < b.first; } const int INF = 0x3f3f3f3f; string tostring(long long int Number) { string String; ostringstream Convert; Convert << Number; String = Convert.str(); return String; } long long int toint(string String) { stringstream Convert(String); long long int Number = 0; Convert >> Number; return Number; } int Lower_bound(vector<int> v, int k) { vector<int>::iterator low; low = lower_bound(v.begin(), v.end(), k); int lower; lower = (low - v.begin()) - 1; return lower; } int Upper_bound(vector<int> v, int k) { vector<int>::iterator up; up = upper_bound(v.begin(), v.end(), k); int upper; upper = (up - v.begin()); return upper; } char pr[33] = {'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~', ' '}; bool pck(char ch) { for (int i = 0; i < 33; i++) { if (ch == pr[i]) return true; } } long long int bigmod(long long int b, long long int p, long long int m) { long long int x; if (p == 0) return 1 % m; x = bigmod(b, p / 2, m); x = (x * x) % m; if (p % 2 == 0) x = x; else x = (x * b) % m; return x; } bool status[100000005]; vector<int> Prime; void sieve() { long long int i, j, N; N = 100000; long long int sq = sqrt(N); for (i = 4; i <= N; i += 2) status[i] = 1; for (i = 3; i <= sq; i += 2) { if (status[i] == 0) { for (j = i * i; j <= N; j += i) status[j] = 1; } } status[1] = 1; for (i = 1; i <= N; i++) { if (status[i] == 0) Prime.push_back(i); } } long long int ReverseI(long long int n) { long long int x = 0; while (n != 0) { x = x * 10 + n % 10; n = n / 10; } return x; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; string second; cin >> second; int i; for (i = 0; i < n - 1; i++) { if (second[i] > second[i + 1]) { cout << "YES" << endl; cout << i + 1 << " " << i + 2 << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, 0, -1}; int dy[] = {0, -1, 1, 0}; int pct(int x) { return __builtin_popcount(x); } template <typename T> T _gcd(T __a, T __b) { return !__b ? __a : _gcd(__b, __a % __b); } template <typename T> T _lcm(T __a, T __b) { return abs((__a / _gcd(__a, __b)) * __b); } template <typename T> T _pow(T __n, T __p) { if (__p <= 1) { return (__p == 1) ? __n : 1; } T R = 1; if (__p % 2) return __n * _pow(__n, __p - 1); else R = _pow(__n, __p / 2); return R * R; } const int MOD = 1e9 + 7; const int N = 2e5 + 5e2; string s, tmp; int n; void Solve() { cin >> n >> s; tmp = s; sort(tmp.begin(), tmp.end()); if (tmp == s) { cout << "NO" << endl; } else { cout << "YES" << endl; int L, R; for (int i = 0; i < n - 1; i++) { if (s[i + 1] < s[i]) { L = i + 1, R = i + 2; break; } } cout << L << ' ' << R << endl; } } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int Tc = 1; while (Tc--) Solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } string bin(int x) { string s = ""; while (x > 0) { if (x % 2) s.push_back('1'); else s.push_back('0'); x = x / 2; } reverse(s.begin(), s.end()); return s; } int num(string t) { reverse(t.begin(), t.end()); int x = 0; for (long long int i = 0; i < t.size(); i++) { x = x + pow(2, i) * (t[i] - 48); } return x; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); std::cout.precision(12); int n; cin >> n; string s; cin >> s; for (long long int i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { cout << "YES\n"; cout << i + 1 << " " << i + 2; return 0; } } cout << "NO"; }
#include <bits/stdc++.h> using namespace std; void ok() { int n; cin >> n; string str; cin >> str; for (int i = 1; i < n; i++) { if (str[i] < str[i - 1]) { cout << "YES" << endl; cout << i << " " << i + 1 << endl; return; } } cout << "NO" << endl; return; } int main() { ok(); return 0; }
#include <bits/stdc++.h> using namespace std; long long i, j, k, l, n, m, flag; long long a[200009]; string s; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> s; for (i = 1; i < s.length(); i++) { if (s[i] < s[i - 1]) { swap(s[i], s[i - 1]); cout << "YES" << '\n' << i << ' ' << i + 1 << '\n'; exit(0); } } cout << "NO" << '\n'; exit(0); }
#include <bits/stdc++.h> using namespace std; int main() { string pal; long n; cin >> n; cin >> pal; for (long i = 1; i < n; i++) { if (pal[i] - pal[i - 1] < 0) { cout << "YES" << endl; cout << i << " " << i + 1 << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s; cin >> s; for (int i = 1; i < n; ++i) { if (s[i] < s[i - 1]) { cout << "YES\n"; cout << i << ' ' << i + 1 << "\n"; return 0; } } cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e6; long long n, m, x, i, z, cnt, sum, rem, tre, ert, ans, used[N]; vector<long long> v, v1; vector<pair<string, string> > p; set<char> second; string s, s1, s2, s3, s4; map<string, long long> mp; char g; int main() { ios_base::sync_with_stdio(0); cin >> n >> s; for (long long i = 0; i < s.size() - 1; i++) { if (s[i] > s[i + 1]) { cout << "YES" << endl; cout << i + 1 << " " << i + 2; return 0; } } cout << "NO"; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; int main() { ll n, i; cin >> n; string s; cin >> s; ll cnt = 0; for (ll i = (ll)0; i < (ll)n - 1; ++i) { if (s[i] > s[i + 1]) { cout << "YES" << endl; cout << i + 1 << " " << i + 2 << endl; exit(0); } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 300100; char str[maxn]; int main() { int n, i, j, l, r; scanf("%d %s", &n, str); l = r = -1; for (i = 0; i + 1 < n; i++) { if (str[i] > str[i + 1]) { l = i; break; } } if (l == -1) printf("NO\n"); else { printf("YES\n%d %d\n", l + 1, l + 2); } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int LINF = 0x3f3f3f3f3f3f3f3fll; const int MOD = 1e9 + 7; const int MAX = 1e5 + 10; int main() { ios::sync_with_stdio(false); cin.tie(0); ; int n; cin >> n; string st; cin >> st; int alfa[27]; memset(alfa, -1, sizeof(alfa)); int final = 'z' - 'a'; for (int i = 0; i < n; i++) { int letter = st[i] - 'a'; for (int j = letter + 1; j <= final; j++) { if (alfa[j] != -1) { cout << "YES" << endl; cout << alfa[j] << " " << i + 1 << endl; return 0; } } alfa[letter] = i + 1; } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; void solve(); long long fact[200001]; long long inf = 1e18; long long z = 1e9 + 7; vector<int> dr{0, 0, -1, 1}, dc{-1, 1, 0, 0}; long long n, m; bool valid(long long x, long long y) { if (x >= 0 && x <= n - 1 && y >= 0 && y <= m - 1) return 1; else return 0; } long long gdp(long long a, long long b) { return (a - (a % b)); } long long gcd(long long a, long long b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } long long power(long long a, long long b, long long p) { if (b == 0) return 1; long long c = power(a, b / 2, p); if (b % 2 == 0) return ((c * c) % p); else return ((((c * c) % p) * a) % p); } long long inverse(long long a, long long n) { return power(a, n - 2, n); } long long max(long long a, long long b) { if (a > b) return a; return b; } long long min(long long a, long long b) { if (a < b) return a; return b; } long long ncr(long long n, long long r) { if (n < r || (n < 0) || (r < 0)) return 0; return ((((fact[n] * inverse(fact[r], z)) % z) * inverse(fact[n - r], z)) % z); } long long mods(long long n) { if (n > 0) return n; else return n * -1; } bool isprime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } bool b1 = 0; vector<long long> adj[100001]; bool vis[100001] = {0}; long long color[100001]; bool ok = 1; long long endi; long long parent[100001] = {0}; long long flag; long long st; vector<long long> prms; bool fun(pair<long long, long long> p1, pair<long long, long long> p2) { return p1.second < p2.second; } int main() { long long t = 1; while (t--) { long long n; cin >> n; string s; cin >> s; long long x, y; for (long long i = 0; i < n - 1; i++) { if (s[i + 1] >= s[i]) { continue; } else { cout << "YES\n"; cout << i + 1 << " " << i + 2 << "\n"; return 0; } } cout << "NO"; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a = 0, b = 0, flag = 0; if (n == 1) { cout << "NO" << endl; } else { for (int i = 0; i < n - 1; i++) { if (int(s[i + 1]) < int(s[i])) { flag = 1; a = i + 1; b = i + 2; break; } } if (flag == 0) { cout << "NO" << endl; } else { cout << "YES" << endl; cout << a << " " << b << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { cout << "YES" << endl; cout << i + 1 << ' ' << i + 2 << endl; return 0; } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 50; char s[N]; int main() { int n; scanf("%d%s", &n, &s); for (int i = 1; i < n; i++) { if (s[i - 1] > s[i]) { puts("YES"); printf("%d %d", i, i + 1); exit(0); } } puts("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i; string s; cin >> n >> s; for (i = 1; i < n; i++) { if (s[i] < s[i - 1]) { puts("YES"); cout << i << " " << i + 1 << endl; return 0; } } puts("NO"); }
#include <bits/stdc++.h> using namespace std; int main() { long long n; while (cin >> n) { string s; cin >> s; long long x = 0; long long y = 0; long long flag = 0; for (long long i = 0; i < s.size() - 1; i++) { if (s[i] > s[i + 1]) { x = i + 1; y = i + 2; flag = 1; break; } } if (flag == 0) { cout << "NO" << endl; } else { cout << "YES" << endl << x << " " << y << endl; } } }
#include <bits/stdc++.h> using namespace std; const int siz = 1e5; long long a[siz]; void fast() { std::ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); } int main() { fast(); int n; cin >> n; string s; cin >> s; int z = 0, x, y; for (int i = 1; i < n; i++) { if (s[i] < s[i - 1]) { z = 1; cout << "YES\n"; cout << i << " " << i + 1; break; } } if (z == 0) cout << "NO"; }
#include <bits/stdc++.h> using namespace std; int main() { string s; long long n, i = 0; cin >> n; cin >> s; while (i < n - 1) { if (s[i + 1] < s[i]) { cout << "YES" << endl; cout << i + 1 << " " << i + 2; break; } i++; } if (i == (n - 1)) cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int maxi = -1, maxiidx; for (int i = 0; i < n; i++) { if (s[i] - 'a' < maxi && maxi != -1) { cout << "YES" << endl; cout << maxiidx << " " << i + 1; return 0; } if (s[i] - 'a' > maxi) { maxiidx = i + 1; maxi = s[i] - 'a'; } } cout << "NO"; return 0; return 0; }
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long M1 = 1000000007; long long M2 = 67280421310721; long long M3 = 998244353; long long INF = 1e18; long long power(long long a, long long b, long long mod) { long long ans = 1; long long prod = a; while (b) { if (b % 2) ans = (ans * prod) % mod; prod = (prod * prod) % mod; b /= 2; } return ans; } long long inv(long long a, long long mod) { return power(a, mod - 2, mod); } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long fact(long long n, long long mod) { long long f = 1; for (long long i = 1; i <= n; i++) f = (f * i) % mod; return f; } long long ncr(long long n, long long r, long long mod) { if (mod == 1) { return (fact(n, mod) / fact(r, mod)) / fact(n - r, mod); } return (((fact(n, mod) * inv(fact(r, mod), mod)) % mod) * inv(fact(n - r, mod), mod)) % mod; } void solve() { long long n; cin >> n; string s; cin >> s; long long i; long long flag = 0; for (i = 1; i < n; i++) { if (s[i] < s[i - 1]) { flag = 1; break; } } if (flag == 0) { cout << "NO" << '\n'; } else { cout << "YES" << '\n'; cout << i << " " << i + 1 << '\n'; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(10); auto start = high_resolution_clock::now(); long long i, t = 1; for (i = 1; i <= t; i++) solve(); auto stop = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop - start); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q; string s, ss; cin >> l >> s; ss = s; sort(ss.begin(), ss.end()); if (s == ss) { cout << "NO\n"; return 0; } cout << "YES\n"; for (i = 1; i < l; i++) { if (s[i] < s[i - 1]) { cout << i << ' ' << i + 1 << '\n'; return 0; } } return 0; }
#include <bits/stdc++.h> const int N = 300000; int n; char s[N + 1]; int main() { scanf("%d%s", &n, s); int p = -1; for (int i = 0; i < n - 1; ++i) if (s[i] > s[i + 1]) p = i; if (p != -1) { printf("YES\n"); printf("%d %d\n", p + 1, p + 2); } else printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string str; long long mxchar = 0, n, j; cin >> n; cin >> str; for (long long i = 0; i < str.size(); i++) { if (mxchar > str[i] - 'a') { cout << "YES\n"; cout << j + 1 << " " << i + 1 << endl; return 0; } long long tt = str[i] - 'a'; if (mxchar < tt) mxchar = tt, j = i; } cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 300005; const int MOD = 1e9 + 7; char s[N]; int main() { int n; cin >> n >> s + 1; for (int i = 2; i <= (n); ++i) { if (s[i] < s[i - 1]) { puts("YES"); cout << i - 1 << " " << i << endl; return 0; } } puts("NO"); return 0; }
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; string char_to_str(char c) { string tem(1, c); return tem; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int n; cin >> n; string s; cin >> s; string s1; s1 = s; sort(s1.begin(), s1.end()); if (s == s1) { cout << "NO"; } else { int i = 0; for (i = 0; i < s.length() - 1; ++i) { if (s[i] > s[i + 1]) { break; } } cout << "YES" << endl; cout << i + 1 << " " << i + 2; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 12; string s; int a[26]; int main() { ios::sync_with_stdio(0), cin.tie(0); int n; cin >> n; cin >> s; int ind = -1; for (int i = 1; i < n; i++) { if (s[i - 1] > s[i]) { ind = i; } } if (ind == -1) { cout << "NO"; return 0; } cout << "YES\n"; cout << ind << " " << ind + 1; }
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; string s; cin >> s; map<long long, long long> m; set<long long> set; set.insert(s[0] - 'a'); m[s[0] - 'a'] = 1; long long flag = 0, l, r; for (long long i = 1; i < s.length(); i++) { long long x = s[i] - 'a'; auto it = set.end(); it--; if (*it > x) { flag = 1; l = m[*it]; r = i + 1; break; } else { set.insert(x); m[x] = i + 1; } } if (flag) { cout << "YES\n"; cout << l << " " << r << "\n"; } else cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, k, l; string s; cin >> l >> s; int fl = 0; for (i = 0; i < l - 1; i++) if (s[i] > s[i + 1]) { fl = 1; break; } if (fl) { cout << "YES\n"; cout << i + 1 << " " << i + 2; } else cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; bool cmp(char a, char b) { return a <= b; } int main() { int n; cin >> n; string s; cin >> s; int i; for (i = 1; i < n; i++) { if (s[i] < s[i - 1]) { cout << "YES" << endl; cout << i << " " << i + 1 << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; string str; int main() { cin >> n; cin >> str; for (int i = 0; i < n - 1; i++) { if (str[i] > str[i + 1]) { cout << "YES" << endl; cout << i + 1 << ' ' << i + 2 << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, l, r; string s; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0); cin >> n; cin >> s; for (i = 1; i < n; i++) { if (s[i] < s[i - 1]) { cout << "YES" << endl; cout << i << " " << i + 1 << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int n; cin >> n; string second; cin >> second; long long int l = -1, r = -1; for (long long int i = 0; i < n - 1; i++) { if (second[i] > second[i + 1]) { l = i, r = i + 1; break; } } if (l == -1) { cout << "NO"; } else { cout << "YES" << "\n"; cout << l + 1 << " " << r + 1; } return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s; cin >> s; string s1 = s; sort(s1.begin(), s1.end()); if (s == s1) { cout << "NO"; return 0; } int pos[26]; for (int j = 0; j <= 25; j++) pos[j] = -1; cout << "YES" << '\n'; for (int i = 0; i < (int)s.size(); i++) { for (int j = 25; j > s[i] - 'a'; j--) { if (pos[j] != -1) { cout << pos[j] + 1 << " " << i + 1 << '\n'; return 0; } } pos[s[i] - 'a'] = i; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int flag = 0; for (int i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { flag = 1; cout << "YES" << endl; cout << i + 1 << " " << i + 2; break; return 0; } } if (flag == 0) { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; string s; cin >> n >> s; for (int i = 1; i < n; ++i) if (s[i - 1] > s[i]) { cout << "YES\n" << i << ' ' << i + 1 << endl; return 0; } cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; char a[300010]; int main() { int n, i; cin >> n; cin >> a + 1; for (i = 1; i < n; i++) { if (a[i] > a[i + 1]) { cout << "YES" << endl; cout << i << ' ' << i + 1; return 0; } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; string s; cin >> s; for (i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { cout << "YES" << endl; cout << i + 1 << " " << i + 2 << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long res = 1; a = a % 1000000007; while (b > 0) { if (b & 1) { res = (res * a) % 1000000007; b--; } a = (a * a) % 1000000007; b >>= 1; } return res; } long long fermat_inv(long long y) { return power(y, 1000000007 - 2); } long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t = 1; while (t--) { int n; cin >> n; string s; cin >> s; int check = -1; for (int i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { check = i + 1; break; } } if (check == -1) { cout << "NO\n"; } else { cout << "YES\n"; cout << check << " " << (check + 1) << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, flag = 0; string s; cin >> n >> s; for (i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { flag = 1; break; } } if (flag == 0) { cout << "NO"; return 0; } cout << "YES" << endl; cout << i + 1 << " " << i + 2; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxx = 3e5 + 100; string s; int n; int main() { while (scanf("%d", &n) != EOF) { cin >> s; int len = s.length(); int flag = 0; int i; for (i = 1; i < len; i++) { if (s[i] < s[i - 1]) { flag = 1; break; } } if (flag == 0) cout << "NO" << endl; else cout << "YES" << endl << i << " " << i + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int c = 0, y, n, i, j; string x; cin >> n >> x; for (i = 0; i < n - 1; i++) { if (x[i] > x[i + 1]) { cout << "YES\n" << i + 1 << " " << i + 2; c = 1; break; } } if (c == 0) cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long i, n, l, c = 0; cin >> n; string s; cin >> s; for (i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { cout << "YES" << endl; cout << i + 1 << " " << i + 2 << endl; return 0; } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; bool flag = false; int i; for (i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { flag = true; break; } } if (!flag) cout << "NO"; else { cout << "YES" << '\n'; cout << i + 1 << " " << i + 2; } }
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; void solve() { long long int n; cin >> n; string s; cin >> s; string str = s; sort(s.begin(), s.end()); long long int idx1 = -1; long long int idx2 = -1; bool check = true; if (s == str) { cout << "NO" << "\n"; ; return; } else { for (int i = 0; i < str.length(); i++) { if (s[i] == str[i]) continue; else { check = false; idx1 = i + 1; for (int j = i + 1; j < str.length(); j++) { if (str[j] == s[i]) { idx2 = j + 1; break; } } } if (check == false) break; } } cout << "YES" << "\n"; ; cout << idx1 << " " << idx2 << "\n"; ; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; const long long MOD = (1e9) + 7; const long double EPS = 0.0000001; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string s; cin >> s; bool flag = true; int where = 0; for (int i = 1; i < n; i++) { if (s[i] - s[i - 1] < 0) { flag = false; where = i + 1; } } if (flag) { cout << "NO\n"; } else { cout << "YES\n"; cout << where - 1 << " " << where << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ; cin >> n; cin >> s; for (int i = 1; i < n; i++) { if (s[i - 1] > s[i]) { cout << "YES" << endl; cout << i << " " << i + 1 << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char sub[n]; for (int i = 0; i < n; i++) { cin >> sub[i]; } bool check = true; for (int i = 0; i < n - 1; i++) { if (sub[i] > sub[i + 1]) { cout << "YES" << endl; cout << i + 1 << " " << i + 1 + 1 << endl; check = false; break; } } if (check == true) { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, ans1, ans2; cin >> n; string s, t; cin >> s; t = s; sort(t.begin(), t.end()); if (t == s) { cout << "NO"; return 0; } char c; for (i = 0; i < n; i++) { if (s[i] != t[i]) { c = t[i]; ans1 = i + 1; break; } } for (j = i; j < n; j++) { if (s[j] == c) { ans2 = j + 1; break; } } cout << "YES" << endl << ans1 << " " << ans2; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int l, r, tr = 0; for (int i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { char t = s[i]; s[i] = s[i + 1]; s[i + 1] = t; l = i + 1; r = i + 2; tr = 1; break; } } if (tr == 1) { cout << "YES" << endl; cout << l << " " << r; } else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> char s[300005]; char t[300005]; long po[300005]; int main() { long n, x = 1; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf(" %c", &s[i]); } t[0] = s[0]; int p = 0; int k = 1; char ch = t[0]; po[0] = 0; for (int j = 1; j < n; j++) { if (s[j] != ch) { t[k++] = s[j]; ch = s[j]; p = j; po[x++] = j; continue; } } int a, b, flag = 0; for (int i = 0; i < strlen(t); i++) { for (int j = i + 1; j < strlen(t); j++) { if (t[j] < t[i]) { flag = 1; a = po[i] + 1; b = po[j] + 1; break; } } if (flag == 1) break; } if (flag == 0) printf("NO\n"); if (flag == 1) printf("YES\n%ld %ld\n", a, b); return 0; }
#include <bits/stdc++.h> using namespace std; char str[300005]; int main() { int n; while (~scanf("%d", &n)) { scanf("%s", str + 1); int temp = (int)str[1]; int pos = -1; for (int i = 2; i <= n; i++) { int x = (int)str[i]; if (x < temp) { pos = i; break; } temp = x; } if (pos == -1) cout << "NO" << endl; else { cout << "YES" << endl; cout << pos - 1 << " " << pos << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; string s; cin >> n >> s; for (int x = 1; x < n; x++) { if (s[x - 1] > s[x]) { cout << "YES\n"; cout << x << ' ' << x + 1 << '\n'; return 0; } } cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int k = 0; for (int i = 1; i < n; i++) { if (s[i] < s[i - 1]) { k = i; } } if (k) printf("YES\n%d %d", k, k + 1); else printf("NO"); }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { cout << "YES" << endl; cout << i + 1 << " " << i + 2 << endl; return 0; } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s, s1; cin >> n >> s; s1 = s; for (unsigned i = 1; i < s.length(); i++) { if (s[i] < s[i - 1]) { cout << "YES\n" << i << ' ' << i + 1; return 0; } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; long long int add(long long int a, long long int b) { return (a % 100000000 + b % 100000000) % 100000000; } long long int sub(long long int a, long long int b) { return (a % 100000000 - b % 100000000 + 100000000) % 100000000; } long long int mul(long long int a, long long int b) { return (a % 100000000 * b % 100000000) % 100000000; } long long int poww(long long int a, long long int b) { long long int res = 1; while (b) { if (b & 1) { res *= a; } a = a * a; b >>= 1; } return res; } long long int poww(long long int a, long long int b, long long int MOD) { long long int res = 1; while (b) { if (b & 1) { res *= a; res %= MOD; } a = a * a; a %= MOD; b >>= 1; } return res; } int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s; cin >> s; string t = s; sort((t).begin(), (t).end()); if (t == s) { cout << "NO\n"; } else { for (int i = 1; i < n; i++) if (s[i] < s[i - 1]) { cout << "YES\n" << i << " " << i + 1; return 0; } } return 0; }
#include <bits/stdc++.h> const int OO = 0x3f3f3f3f; using namespace std; void Play(); int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int main() { int n; cin >> n; string s; cin >> s; for (int i = 1; i < s.size(); ++i) { if (s[i] < s[i - 1]) { cout << "YES" << endl; cout << i << " " << i + 1 << endl; return 0; } } cout << "NO" << endl; return 0; } void Play() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { long long int n, i, l, r, a; string s, test; bool ans; cin >> n >> test; ans = false; for (i = 0; i < n - 1; i++) { if (test[i] > test[i + 1]) { ans = true; l = i + 1; break; } } r = l + 1; if (ans) { cout << "YES\n" << l << " " << r << '\n'; } else { cout << "NO\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; string ss = s; sort(ss.begin(), ss.end()); if (ss.compare(s) == 0) { cout << "NO" << endl; } else { int l, r; for (int i = 1; i < n; ++i) { if (s[i] < s[i - 1]) { l = i - 1; r = i; break; } } cout << "YES" << endl; cout << l + 1 << " " << r + 1; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int now = 0, nxt = 1; long long dp[2][10]; memset(dp, -1, sizeof(dp)); dp[0][0] = 0; while (n--) { int k; cin >> k; vector<long long> v[4]; for (int i = 0; i < k; i++) { long long c, d; cin >> c >> d; v[c].push_back(d); } sort(v[1].begin(), v[1].end(), greater<long long>()); sort(v[2].begin(), v[2].end(), greater<long long>()); sort(v[3].begin(), v[3].end(), greater<long long>()); memcpy(dp[nxt], dp[now], sizeof(dp[now])); for (int i = 0; i < 10; i++) { if (dp[now][i] == -1) continue; for (int j = 1; j <= 3; j++) { if ((int)v[j].size() != 0) { dp[nxt][(i + 1) % 10] = max(dp[nxt][(i + 1) % 10], dp[now][i] + v[j][0] * (1 + ((i + 1) == 10))); } } if ((int)v[1].size() >= 3) dp[nxt][(i + 3) % 10] = max( dp[nxt][(i + 3) % 10], dp[now][i] + v[1][0] * (1 + ((i + 3) >= 10)) + v[1][1] + v[1][2]); if ((int)v[1].size() >= 2) dp[nxt][(i + 2) % 10] = max(dp[nxt][(i + 2) % 10], dp[now][i] + v[1][0] * (1 + ((i + 2) >= 10)) + v[1][1]); if ((int)v[2].size() != 0 && (int)v[1].size() != 0) dp[nxt][(i + 2) % 10] = max( dp[nxt][(i + 2) % 10], dp[now][i] + v[2][0] + v[1][0] + max(v[1][0], v[2][0]) * ((i + 2) >= 10)); } swap(now, nxt); } long long ans = 0; for (int i = 0; i < 10; i++) ans = max(ans, dp[now][i]); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int MAX = 2e5 + 5; const long long MAX2 = 11; const long long MOD = 998244353; const long long INF = 2e18; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0}; const double pi = acos(-1); const double EPS = 1e-9; const int block = 450; int n, k, c, x, id; long long dp[MAX][10], z[MAX][7], cnt[MAX][4]; priority_queue<int> pq[4]; long long f(int nw, int st) { if (nw > n) return 0; if (dp[nw][st] != -1) return dp[nw][st]; long long ret = f(nw + 1, st), tmp; tmp = max(z[nw][1], max(z[nw][4], z[nw][6])); ret = max(ret, f(nw + 1, (st + 1) % 10) + tmp + (st == 9 ? tmp : 0)); if (cnt[nw][1] >= 2) { ret = max(ret, f(nw + 1, (st + 2) % 10) + z[nw][1] + z[nw][2] + (st >= 8 ? z[nw][1] : 0)); } if (cnt[nw][1] && cnt[nw][2]) { ret = max(ret, f(nw + 1, (st + 2) % 10) + z[nw][1] + z[nw][4] + (st >= 8 ? max(z[nw][4], z[nw][1]) : 0)); } if (cnt[nw][1] == 3) { ret = max(ret, f(nw + 1, (st + 3) % 10) + z[nw][1] + z[nw][2] + z[nw][3] + (st >= 7 ? z[nw][1] : 0)); } return dp[nw][st] = ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (long long i = 1; i <= n; ++i) { cin >> k; for (long long j = 1; j <= 3; ++j) while (!pq[j].empty()) pq[j].pop(); for (long long j = 1; j <= k; ++j) { cin >> c >> x; pq[c].push(x); } id = 0; for (long long j = 1; j <= 3; ++j) { if (pq[1].empty()) break; z[i][++id] = pq[1].top(); cnt[i][1]++; pq[1].pop(); } id = 3; for (long long j = 1; j <= 2; ++j) { if (pq[2].empty()) break; z[i][++id] = pq[2].top(); cnt[i][2]++; pq[2].pop(); } id = 5; for (long long j = 1; j <= 1; ++j) { if (pq[3].empty()) break; z[i][++id] = pq[3].top(); cnt[i][3]++; pq[3].pop(); } } memset(dp, -1, sizeof dp); cout << f(1, 0) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void _dbg(char const *s, const T &t) { cout << s << "=" << t << endl; } template <typename T, typename... TA> void _dbg(char const *s, const T &t, const TA &...ta) { while (*s != ',') cout << *s++; cout << "=" << t << ","; _dbg(s + 1, ta...); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << "(" << p.first << "," << p.second << ")"; } template <typename T> ostream &print_iterable(ostream &os, T beg, T end) { os << '['; for (auto it = beg; it != end; ++it) { if (it != beg) os << ", "; os << *it; } return os << ']'; } template <typename T, size_t N> ostream &operator<<(ostream &os, const array<T, N> &x) { return print_iterable(os, x.begin(), x.end()); } template <typename T> ostream &operator<<(ostream &os, const vector<T> &x) { return print_iterable(os, x.begin(), x.end()); } template <typename T> ostream &operator<<(ostream &os, const set<T> &x) { return print_iterable(os, x.begin(), x.end()); } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &x) { return print_iterable(os, x.begin(), x.end()); } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &x) { return print_iterable(os, x.begin(), x.end()); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &x) { return print_iterable(os, x.begin(), x.end()); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &x) { return print_iterable(os, x.begin(), x.end()); } using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; const int N = 2750133; void Solve() { int n, k, c, d; vector<ll> dp(10); vector<vector<pii>> steps = {{{3, 1}}, {{2, 1}}, {{2, 1}, {1, 1}}, {{1, 1}}, {{1, 2}}, {{1, 3}}}; dp[0] = 1; scanf("%d", &n); while (n--) { scanf("%d", &k); vector<vector<int>> vc(4); while (k--) { scanf("%d%d", &c, &d); vc[c].push_back(d); } for (int i = 1; i < 4; ++i) { sort((vc[i]).begin(), (vc[i]).end()); reverse((vc[i]).begin(), (vc[i]).end()); } vector<ll> tmpdp = dp; for (auto &step : steps) { vector<int> tmp; bool flag = true; int cnt = 0; ll sum = 0; for (auto &x : step) { if ((int)vc[x.first].size() < x.second) { flag = false; continue; } cnt += x.second; for (int i = 0; i < x.second; ++i) { tmp.push_back(vc[x.first][i]); sum += tmp.back(); } } if (!flag) { continue; } sort((tmp).begin(), (tmp).end()); for (int i = 0; i < 10 - cnt; ++i) { if (!dp[i]) continue; tmpdp[i + cnt] = max(tmpdp[i + cnt], dp[i] + sum); } for (int i = 10 - cnt; i < 10; ++i) { if (!dp[i]) continue; tmpdp[i + cnt - 10] = max(tmpdp[i + cnt - 10], dp[i] + sum + tmp.back()); } } swap(dp, tmpdp); } ll mx = 0; for (auto &x : dp) { mx = max(mx, x); } printf("%lld\n", mx - 1); } int main() { Solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 888; long long dp[maxn][12]; void solve() { long long n; scanf("%lld", &n); memset(dp, -1, sizeof(dp)); dp[0][1] = 0; vector<long long> v[4]; for (long long i = 1; i <= n; i++) { for (long long j = 0; j < 4; j++) v[j].clear(); long long k; scanf("%lld", &k); while (k--) { long long c, d; scanf("%lld %lld", &c, &d); v[c].push_back(d); } for (long long j = 1; j <= 3; j++) { sort(v[j].begin(), v[j].end()); reverse(v[j].begin(), v[j].end()); } for (long long prec = 0; prec <= 9; prec++) { if (dp[i - 1][prec] < 0) continue; long long val = LLONG_MIN / 10; if (!v[1].empty()) val = max(val, v[1][0]); if (!v[2].empty()) val = max(val, v[2][0]); if (!v[3].empty()) val = max(val, v[3][0]); if (prec == 0) val *= 2; if (val > 0) dp[i][(prec + 1) % 10] = max(dp[i][(prec + 1) % 10], dp[i - 1][prec] + val); val = LLONG_MIN / 10; if (!v[1].empty() && !v[2].empty()) { long long temp = v[1][0] + v[2][0]; long long mx = max(v[1][0], v[2][0]); if (prec == 0 || prec == 9) temp += mx; val = max(val, temp); } if (v[1].size() >= 2) { long long temp = v[1][0] + v[1][1]; long long mx = max(v[1][0], v[1][1]); if (prec == 0 || prec == 9) temp += mx; val = max(val, temp); } if (val > 0) dp[i][(prec + 2) % 10] = max(dp[i][(prec + 2) % 10], dp[i - 1][prec] + val); val = LLONG_MIN / 10; if (v[1].size() >= 3) { long long temp = v[1][0] + v[1][1] + v[1][2]; long long mx = max(v[1][0], max(v[1][2], v[1][1])); if (prec == 0 || prec == 9 || prec == 8) temp += mx; val = max(val, temp); } if (val > 0) dp[i][(prec + 3) % 10] = max(dp[i][(prec + 3) % 10], dp[i - 1][prec] + val); dp[i][prec] = max(dp[i][prec], dp[i - 1][prec]); } } long long ans = 0; for (long long i = 0; i <= 9; i++) ans = max(ans, dp[n][i]); cout << ans << endl; } signed main() { solve(); }
#include <bits/stdc++.h> using namespace std; const int oo = 1e9 + 5; const int MOD = 1e9; const long long ooll = 1e18 + 5; const int N = 2e5 + 5; const int M = 401; const int lgN = 18; vector<long long> play(vector<long long> dp, int x) { vector<long long> res(10); for (int i = 0; i < 10; ++i) { int j = (i < 9) ? (i + 1) : 0; res[j] = dp[i] + x + (j == 0 ? x : 0); } return res; } void solve() { int n, m, i, j; cin >> n; vector<long long> dp(10, -ooll); dp[0] = 0; for (i = 0; i < n; ++i) { int k; cin >> k; vector<vector<int>> v(3); for (j = 0; j < k; ++j) { int x, y; cin >> x >> y; v[x - 1].push_back(y); } for (j = 0; j < 3; ++j) if (!v[j].empty()) { sort(v[j].begin(), v[j].end(), [](int a, int b) { return a > b; }); } vector<long long> dq(dp.begin(), dp.end()); if ((int)v[0].size() >= 3) { auto now = play(play(play(dp, v[0][0]), v[0][1]), v[0][2]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); now = play(play(play(dp, v[0][0]), v[0][2]), v[0][1]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); now = play(play(play(dp, v[0][1]), v[0][0]), v[0][2]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); now = play(play(play(dp, v[0][1]), v[0][2]), v[0][0]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); now = play(play(play(dp, v[0][2]), v[0][0]), v[0][1]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); now = play(play(play(dp, v[0][2]), v[0][1]), v[0][0]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); } if ((int)v[0].size() >= 2) { auto now = play(play(dp, v[0][0]), v[0][1]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); now = play(play(dp, v[0][1]), v[0][0]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); } if ((int)v[0].size() >= 1) { auto now = play(dp, v[0][0]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); } if ((int)v[0].size() >= 1 && (int)v[1].size() >= 1) { auto now = play(play(dp, v[0][0]), v[1][0]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); now = play(play(dp, v[1][0]), v[0][0]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); } if ((int)v[1].size() >= 1) { auto now = play(dp, v[1][0]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); } if ((int)v[2].size() >= 1) { auto now = play(dp, v[2][0]); for (int i = 0; i < 10; ++i) dq[i] = max(dq[i], now[i]); } dp = dq; } long long ans = -ooll; for (auto it : dp) ans = max(ans, it); cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; for (int tc = 1; tc <= t; ++tc) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long int dp[200005][10]; long long int dp1[10]; long long int arr[200005][4]; vector<long long int> vec[200005][4]; bool check(long long int a, long long int b) { return a > b; } int main() { int n; cin >> n; for (long long int i = 1; i <= n; i++) { int k; cin >> k; for (long long int j = 1; j <= k; j++) { long long int a, b; cin >> a >> b; vec[i][a].push_back(b); } for (long long int j = 1; j <= 3; j++) { sort(vec[i][j].begin(), vec[i][j].end(), check); } } for (long long int i = 0; i <= n; i++) { for (long long int j = 0; j <= 9; j++) { dp[i][j] = -1e18; } } dp[0][0] = 0; for (long long int i = 1; i <= n; i++) { for (int j = 0; j <= 9; j++) { dp1[j] = -1e18; dp1[j] = max(dp1[j], dp[i - 1][j]); } if (vec[i][3].size() != 0) { for (int j = 0; j <= 8; j++) { dp1[j + 1] = max(dp1[j + 1], dp[i - 1][j] + vec[i][3][0]); } dp1[0] = max(dp1[0], dp[i - 1][9] + vec[i][3][0] * 2); } if (vec[i][2].size() != 0) { if (vec[i][1].size() != 0) { long long int maxi = max(vec[i][1][0], vec[i][2][0]); for (int j = 0; j <= 7; j++) { dp1[j + 2] = max(dp1[j + 2], dp[i - 1][j] + vec[i][2][0] + vec[i][1][0]); } dp1[0] = max(dp1[0], dp[i - 1][8] + vec[i][2][0] + vec[i][1][0] + maxi); dp1[1] = max(dp1[1], dp[i - 1][9] + vec[i][2][0] + vec[i][1][0] + maxi); } for (int j = 0; j <= 8; j++) { dp1[j + 1] = max(dp1[j + 1], dp[i - 1][j] + vec[i][2][0]); } dp1[0] = max(dp1[0], dp[i - 1][9] + vec[i][2][0] * 2); } if (vec[i][1].size() != 0) { for (int k = 1; k <= min((long long int)3, (long long int)vec[i][1].size()); k++) { long long int sum = 0; long long int maxi = 0; for (long long int j = 0; j < k; j++) { sum += vec[i][1][j]; maxi = max(maxi, vec[i][1][j]); } for (long long int j = 0; j <= 9; j++) { if (j + k >= 10) { long long int a = (j + k) % 10; dp1[a] = max(dp1[a], dp[i - 1][j] + sum + maxi); } else { long long int a = (j + k); dp1[a] = max(dp1[a], dp[i - 1][j] + sum); } } } } for (long long int j = 0; j <= 9; j++) { if (dp1[j] >= 0) { dp[i][j] = dp1[j]; } } } long long int ans = 0; for (long long int i = 0; i <= 9; i++) { ans = max(ans, dp[n][i]); } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; long long f[10]; long long nf[10]; int w[4][4]; int main() { int n; scanf("%d", &n); memset(f, -1, sizeof f); f[0] = 0; for (int it = 0; it < n; ++it) { int m; scanf("%d", &m); memset(w, 0, sizeof w); while (m--) { int x, y; scanf("%d%d", &x, &y); w[x][3] = -y; sort(w[x], w[x] + 4); } memcpy(nf, f, sizeof nf); for (int i = 0; i < 10; ++i) { if (f[i] == -1) { continue; } for (int a = 0; a <= 3; ++a) { for (int b = 0; a + b * 2 <= 3; ++b) { for (int c = 0; a + b * 2 + c * 3 <= 3; ++c) { vector<int> cur; for (int j = 0; j < a; ++j) { if (w[1][j] < 0) { cur.push_back(w[1][j]); } } for (int j = 0; j < b; ++j) { if (w[2][j] < 0) { cur.push_back(w[2][j]); } } for (int j = 0; j < c; ++j) { if (w[3][j] < 0) { cur.push_back(w[3][j]); } } if ((int)cur.size() == a + b + c) { sort(cur.begin(), cur.end()); long long sum = 0; for (int e : cur) { sum -= e; } int ni = i + a + b + c; if (ni >= 10) { sum -= cur[0]; } nf[ni % 10] = max(nf[ni % 10], f[i] + sum); } } } } } memcpy(f, nf, sizeof f); } long long ans = 0; for (int i = 0; i < 10; ++i) { ans = max(ans, f[i]); } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<vector<vector<long long>>> p(n, vector<vector<long long>>(4)); for (int i = 0; i < n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int c, d; cin >> c >> d; p[i][c].push_back(d); } for (int j = 1; j <= 3; j++) sort(p[i][j].begin(), p[i][j].end(), greater<long long>()); } vector<vector<long long>> dp(n + 1, vector<long long>(10, -1e18)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 10; j++) { if (dp[i][j] < 0) continue; for (int i1 = 0; i1 <= 3; i1++) { for (int i2 = 0; i2 <= 1; i2++) { for (int i3 = 0; i3 <= 1; i3++) { if (i1 + i2 * 2 + i3 * 3 > 3) break; if (p[i][1].size() < i1) break; if (p[i][2].size() < i2) break; if (p[i][3].size() < i3) break; long long d = 0, c = 0; for (int k = 0; k < i1; k++) { d += p[i][1][k]; c = max(c, p[i][1][k]); } for (int k = 0; k < i2; k++) { d += p[i][2][k]; c = max(c, p[i][2][k]); } for (int k = 0; k < i3; k++) { d += p[i][3][k]; c = max(c, p[i][3][k]); } if (i1 + i2 + i3 + j >= 10) d += c; dp[i + 1][(i1 + i2 + i3 + j) % 10] = max(dp[i + 1][(i1 + i2 + i3 + j) % 10], dp[i][j] + d); } } } } } long long res = 0; for (int i = 0; i < 10; i++) res = max(res, dp[n][i]); cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int n; int k; long long d[N][10]; long long d1[4][2]; vector<int> g[N][4]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> k; for (int j = 1; j <= k; j++) { int x, y; cin >> x >> y; g[i][x].push_back(y); } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= 3; j++) { int sz = (j == 1 ? 3 : 1); sort(g[i][j].rbegin(), g[i][j].rend()); while ((int)g[i][j].size() > sz) g[i][j].pop_back(); } } for (int i = 0; i <= n; i++) for (int j = 0; j < 10; j++) d[i][j] = -LONG_MAX; d[0][0] = 0; for (int i = 1; i <= n; i++) { vector<pair<int, int>> a; for (int j = 1; j <= 3; j++) for (auto x : g[i][j]) a.push_back({j, x}); for (int t = 0; t < 4; t++) d1[t][0] = d1[t][1] = -LONG_MAX; d1[0][0] = 0; sort(a.begin(), a.end()); do { int cur = 0; int cnt = 3; int mx = 0; long long sum = 0; for (auto x : a) { cur++; if (cnt < x.first) break; cnt -= x.first; sum += x.second; mx = max(mx, x.second); d1[cur][0] = max(d1[cur][0], sum); d1[cur][1] = max(d1[cur][1], sum + mx); } } while (next_permutation(a.begin(), a.end())); for (int j = 0; j < 10; j++) { for (int k = 0; k <= 3; k++) { int nxt = (j + k) % 10; int f = ((j + k) >= 10); d[i][nxt] = max(d[i][nxt], d[i - 1][j] + d1[k][f]); } } } long long res = 0; for (int i = 0; i < 10; i++) res = max(res, d[n][i]); cout << res << "\n"; }
#include <bits/stdc++.h> using namespace std; long long n, k, c, d, ans; vector<pair<long long, long long> > tmp, cards[200002]; long long dp[200002][11]; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first < b.first) return true; else if (a.first > b.first) return false; else return a.second > b.second; } void deb() { for (int i = 0; i < n; i++) { long long sez = cards[i].size(); cout << i << ": \n"; for (int j = 0; j < sez; j++) { cout << cards[i][j].first << " " << cards[i][j].second << "\n"; } } } void deb2() { for (int i = 1; i <= n; i++) { long long res = 0; for (int j = 0; j < 10; j++) res = max(res, dp[i][j]); cout << i << "-->" << res << "\n"; } } int main() { ans = 0; cin >> n; for (int i = 0; i <= n; i++) { for (int j = 0; j < 11; j++) { dp[i][j] = -1; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { long long cnt[4]; for (int j = 0; j < 4; j++) cnt[j] = 0; cin >> k; for (int j = 0; j < k; j++) { cin >> c >> d; tmp.push_back(make_pair(c, d)); } sort(tmp.begin(), tmp.end(), cmp); for (int j = 0; j < k; j++) { if (tmp[j].first == 1) { if (cnt[1] < 3) { cards[i].push_back(tmp[j]); cnt[1]++; } } else { if (cnt[tmp[j].first] < 1) { cards[i].push_back(tmp[j]); cnt[tmp[j].first]++; } } } tmp.clear(); } for (int i = 0; i < n; i++) { vector<pair<pair<long long, long long>, long long> > tmp2; long long sez = cards[i].size(); for (int j = 0; j < (1 << sez); j++) { long long cost = 0, cnt = 0, cnt2 = 0, maks = 0; for (int k = 0; k < sez; k++) { if (j & (1 << k)) { cost += cards[i][k].second; cnt += cards[i][k].first; maks = max(maks, cards[i][k].second); cnt2++; } } if (cnt > 3) continue; tmp2.push_back(make_pair(make_pair(cost, cnt2), maks)); } long long sez2 = tmp2.size(); for (int j = 0; j < 10; j++) { if (dp[i][j] == -1) continue; for (int k = 0; k < sez2; k++) { dp[i + 1][(j + tmp2[k].first.second) % 10] = max(dp[i + 1][(j + tmp2[k].first.second) % 10], dp[i][j] + tmp2[k].first.first + (j + tmp2[k].first.second >= 10 ? tmp2[k].second : 0)); } } tmp2.clear(); } for (int i = 0; i < 10; i++) { ans = max(ans, dp[n][i]); } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; const long long N = 200005; long long dp[N][10]; long long p, cur; void solve() { long long n; cin >> n; for (long long i = 0; i < n + 1; i++) { for (long long j = 0; j < 10; j++) dp[i][j] = -1000000000000000007LL; } dp[0][0] = 0; for (long long i = 1; i < n + 1; i++) { long long k; cin >> k; vector<long long> vect[4]; for (long long j = 0; j < k; j++) { long long c, d; cin >> c >> d; vect[c].push_back(d); } sort(vect[1].begin(), vect[1].end()); sort(vect[2].begin(), vect[2].end()); sort(vect[3].begin(), vect[3].end()); long long mx1 = 0, mx2 = 0, mx3 = 0; if ((long long)vect[1].size()) mx1 = vect[1].back(); if ((long long)vect[2].size()) mx2 = vect[2].back(); if ((long long)vect[3].size()) mx3 = vect[3].back(); if ((long long)vect[1].size() >= 3) { long long tot = 0; for (long long j = 1; j <= 3; j++) { tot += vect[1][(long long)vect[1].size() - j]; } for (long long j = 0; j < 10; j++) { p = ((j - 3) + 10) % 10; cur = dp[i - 1][p] + tot; if (j <= 2) { cur += mx1; } dp[i][j] = max(dp[i][j], cur); } } if ((long long)vect[1].size() >= 2) { long long tot = 0; for (long long j = 1; j <= 2; j++) { tot += vect[1][(long long)vect[1].size() - j]; } for (long long j = 0; j < 10; j++) { p = ((j - 2) + 10) % 10; cur = dp[i - 1][p] + tot; if (j <= 1) { cur += mx1; } dp[i][j] = max(dp[i][j], cur); } } if ((long long)vect[2].size() && (long long)vect[1].size()) { long long tot = mx1 + mx2; for (long long j = 0; j < 10; j++) { p = ((j - 2) + 10) % 10; cur = dp[i - 1][p] + tot; if (j <= 1) { cur += max(mx1, mx2); } dp[i][j] = max(dp[i][j], cur); } } long long tot = max(max(mx1, mx2), mx3); for (long long j = 0; j < 10; j++) { p = ((j - 1) + 10) % 10; cur = dp[i - 1][p] + tot; if (j == 0) { cur += tot; } dp[i][j] = max(dp[i][j], cur); dp[i][j] = max(dp[i][j], dp[i - 1][j]); if (dp[i][j] < 0) dp[i][j] = -1000000000000000007LL; } } long long ans = 0; for (long long i = 0; i < 10; i++) { ans = max(ans, dp[n][i]); } cout << ans; } signed main() { std::ios::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 10; const int MOD = 1e9 + 7; int n; vector<long long> dp(10, 0); void solve() { for (int i = 1; i <= (int)(9); i++) dp[i] = -1; cin >> n; for (int _ = 0; _ < (int)(n); _++) { vector<long long> tmp = dp; int k; cin >> k; vector<long long> card[4]; for (int __ = 0; __ < (int)(k); __++) { int co; long long da; cin >> co >> da; card[co].push_back(da); } int l[4]; for (int i = 1; i <= (int)(3); i++) { l[i] = ((int)(card[i]).size()); if (l[i] != 0) sort((card[i]).begin(), (card[i]).end(), greater<long long>()); } if (l[1] > 0) for (int i = 0; i < (int)(10); i++) if (dp[i] != -1) { if (i <= 8) tmp[i + 1] = max(tmp[i + 1], dp[i] + card[1][0]); else tmp[(i + 1) % 10] = max(tmp[(i + 1) % 10], dp[i] + card[1][0] * 2); } if (l[1] > 1) for (int i = 0; i < (int)(10); i++) if (dp[i] != -1) { if (i <= 7) tmp[i + 2] = max(tmp[i + 2], dp[i] + card[1][0] + card[1][1]); else tmp[(i + 2) % 10] = max(tmp[(i + 2) % 10], dp[i] + card[1][0] * 2 + card[1][1]); } if (l[2] > 0) for (int i = 0; i < (int)(10); i++) if (dp[i] != -1) { if (i <= 8) tmp[i + 1] = max(tmp[i + 1], dp[i] + card[2][0]); else tmp[(i + 1) % 10] = max(tmp[(i + 1) % 10], dp[i] + card[2][0] * 2); } if (l[1] > 2) for (int i = 0; i < (int)(10); i++) if (dp[i] != -1) { if (i <= 6) tmp[i + 3] = max(tmp[i + 3], dp[i] + card[1][0] + card[1][1] + card[1][2]); else tmp[(i + 3) % 10] = max(tmp[(i + 3) % 10], dp[i] + card[1][0] * 2 + card[1][1] + card[1][2]); } if (l[1] > 0 && l[2] > 0) for (int i = 0; i < (int)(10); i++) if (dp[i] != -1) { if (i <= 7) tmp[i + 2] = max(tmp[i + 2], dp[i] + card[1][0] + card[2][0]); else tmp[(i + 2) % 10] = max(tmp[(i + 2) % 10], dp[i] + card[1][0] + card[2][0] + max(card[1][0], card[2][0])); } if (l[3] > 0) for (int i = 0; i < (int)(10); i++) if (dp[i] != -1) { if (i <= 8) tmp[i + 1] = max(tmp[i + 1], dp[i] + card[3][0]); else tmp[(i + 1) % 10] = max(tmp[(i + 1) % 10], dp[i] + card[3][0] * 2); } dp = tmp; } long long ans = 0; for (int i = 0; i < (int)(10); i++) ans = max(ans, dp[i]); cout << ans << endl; } int main() { solve(); }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 10; long long dp[N][M]; long long val[N][4][4], dval[N][4][4]; vector<int> g[4]; void brute(int ind, int cost, int mm, int sz, long long sum, int x, int y, int z) { if (mm > 0) { if (val[ind][cost][sz] < sum) { val[ind][cost][sz] = sum; } if (dval[ind][cost][sz] < sum + mm) { dval[ind][cost][sz] = sum + mm; } } for (int c = 1; c <= 3; ++c) { if (c + cost > 3) { break; } if (c == 1 && x < g[c].size()) { brute(ind, cost + c, max(mm, g[c][x]), sz + 1, sum + g[c][x], x + 1, y, z); } if (c == 2 && y < g[c].size()) { brute(ind, cost + c, max(mm, g[c][y]), sz + 1, sum + g[c][y], x, y + 1, z); } if (c == 3 && z < g[c].size()) { brute(ind, cost + c, max(mm, g[c][z]), sz + 1, sum + g[c][z], x, y, z + 1); } } } void find(int ind) { int cost = 0, mm = 0, sz = 0; brute(ind, cost, mm, sz, 0, 0, 0, 0); } long long solveDp(int ind, int pos, int n) { if (ind == n) { return 0; } long long &ret = dp[ind][pos]; if (ret != -1) { return ret; } ret = solveDp(ind + 1, pos, n); for (int cost = 1; cost <= 3; ++cost) { for (int size = 1; size <= 3; ++size) { if (val[ind][cost][size] == -1) { continue; } int npos = pos + size; long long add = val[ind][cost][size]; if (npos >= 10) { npos -= 10; add = dval[ind][cost][size]; } ret = max(ret, solveDp(ind + 1, npos, n) + add); } } return ret; } void solve() { int n; scanf("%d", &n); memset(dp, -1, sizeof dp); memset(val, -1, sizeof(val)); for (int i = 0; i < n; ++i) { priority_queue<int, vector<int>, greater<int> > q[4]; int sz[4] = {0, 3, 1, 1}; int k, c, d; scanf("%d", &k); for (int j = 0; j < k; ++j) { scanf("%d%d", &c, &d); q[c].push(d); if (q[c].size() > sz[c]) { q[c].pop(); } } for (int j = 1; j <= 3; ++j) { g[j].clear(); while (!q[j].empty()) { g[j].push_back(q[j].top()); q[j].pop(); } sort(g[j].begin(), g[j].end()); reverse(g[j].begin(), g[j].end()); } find(i); } printf("%lld\n", solveDp(0, 0, n)); } int main() { solve(); }
#include <bits/stdc++.h> using namespace std; long long i, i1, j, k, k1, t, n, m, res, flag[10], a, b; long long dp[200010][10], c, d; vector<long long> adj[4]; void upd(long long l, array<long long, 3> f) { long long i, d1, j, s; vector<long long> v; for (i = 1; i <= 3; i++) { if (adj[i].size() < f[i - 1]) return; } for (i = 1; i <= 3; i++) { for (j = 0; j < f[i - 1]; j++) { v.push_back(adj[i][j]); } } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); s = v.size(); d1 = 0; for (auto u : v) d1 += u; for (j = 0; j <= 9; j++) { if (s == 0) dp[l][j] = max(dp[l][j], dp[l - 1][j]); else dp[l][j] = max(dp[l][j], dp[l - 1][(j - s + 10) % 10] + d1 + (j < s) * v[0]); } } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (i = 0; i < 200010; i++) { for (j = 0; j <= 9; j++) { dp[i][j] = -(long long)1e18; } } dp[0][0] = 0; for (i = 1; i <= n; i++) { cin >> k; for (j = 0; j <= 3; j++) adj[j].clear(); for (j = 1; j <= k; j++) { cin >> c >> d; adj[c].push_back(d); } for (j = 0; j <= 3; j++) { sort(adj[j].begin(), adj[j].end()); reverse(adj[j].begin(), adj[j].end()); } upd(i, {0, 0, 0}); upd(i, {1, 0, 0}); upd(i, {2, 0, 0}); upd(i, {3, 0, 0}); upd(i, {0, 1, 0}); upd(i, {1, 1, 0}); upd(i, {0, 0, 1}); } res = 0; for (j = 0; j <= 9; j++) res = max(res, dp[n][j]); cout << res << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long long modx(long long Base, long long exponent) { long long ans = 1; if (Base == 1) return Base; while (exponent) { if (exponent & 1) ans = (ans * Base) % 1000000007LL; Base = (Base * Base) % 1000000007LL; exponent = exponent >> 1; } return ans; } long long inmodx(long long num) { return (modx(num, 1000000007LL - 2LL)); } bool cmp(pair<int, int> a, pair<int, int> b) { if (a.second < b.second) return 1; if (a.second > b.second) return 0; if (a.first <= b.first) return 1; return 0; } const int N = (2e5) + 9; const int M = (N << 2) + 9; const int LOGN = ((int)log2(N)) + 3; const int LOGM = ((int)log2(M)) + 3; const int BUCK = 900; vector<long long> cards[N][4]; long long dp[N][10]; pair<long long, long long> dpp[5]; void func(int ind) { int i, j; for (i = (0); i < (4); i++) dpp[i] = {-100000000000011LL, -100000000000011LL}; dpp[0] = {0, 0}; for (i = (1); i < (4); i++) { if ((int)((cards[ind][1]).size()) < i) break; dpp[i].first = 0; for (j = (0); j < (i); j++) { dpp[i].first += cards[ind][1][j]; dpp[i].second = max(dpp[i].second, cards[ind][1][j]); } } if (!cards[ind][2].empty()) { if (cards[ind][2][0] > dpp[1].first) dpp[1] = {cards[ind][2][0], cards[ind][2][0]}; if (!cards[ind][1].empty() && (cards[ind][1][0] + cards[ind][2][0]) > dpp[2].first) dpp[2] = {cards[ind][1][0] + cards[ind][2][0], max(cards[ind][1][0], cards[ind][2][0])}; } if (!cards[ind][3].empty() && cards[ind][3][0] > dpp[1].first) dpp[1] = {cards[ind][3][0], cards[ind][3][0]}; return; } void solve() { int n, i, j, k, a, b; long long ans = -100000000000011LL; cin >> n; for (i = (1); i < (n + 1); i++) { cin >> k; while (k--) { cin >> a >> b; cards[i][a].push_back(b); } sort((cards[i][1]).begin(), (cards[i][1]).end(), greater<int>()); sort((cards[i][2]).begin(), (cards[i][2]).end(), greater<int>()); sort((cards[i][3]).begin(), (cards[i][3]).end(), greater<int>()); } for (i = (0); i < (n + 1); i++) for (j = (0); j < (10); j++) dp[i][j] = -100000000000011LL; dp[0][0] = 0; for (i = (1); i < (n + 1); i++) { func(i); for (j = (0); j < (10); j++) for (k = (0); k < (4); k++) dp[i][j] = max(dp[i][j], dp[i - 1][(j - k + 10) % 10] + ((j < k) ? (dpp[k].first + dpp[k].second) : dpp[k].first)); } for (j = (0); j < (10); j++) ans = max(ans, dp[n][j]); cout << ans << '\n'; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t clk; clk = clock(); int t = 1, cs; cout << fixed << setprecision(6); for (cs = (1); cs < (t + 1); cs++) { solve(); } clk = clock() - clk; cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; long long dp[N][10]; vector<pair<int, int>> v[N]; long long solve(int idx, int pre) { if (idx == n) return 0; long long &ans = dp[idx][pre]; if (~ans) return ans; ans = 0; ans = max(ans, solve(idx + 1, pre)); int sz = v[idx].size(); for (int i = 0; i < sz; i++) { long long cur = 0, curPre = pre; if (curPre == 0) { cur += 2 * v[idx][i].second; } else cur += v[idx][i].second; curPre = (curPre + 1) % 10; ans = max(ans, solve(idx + 1, curPre) + cur); } for (int i = 0; i < sz; i++) { for (int j = 0; j < sz; j++) { if (i == j || v[idx][i].first + v[idx][j].first > 3) continue; long long cur = 0, curPre = pre; if (curPre == 0) cur += 2 * v[idx][i].second; else cur += v[idx][i].second; curPre = (curPre + 1) % 10; if (curPre == 0) cur += 2 * v[idx][j].second; else cur += v[idx][j].second; curPre = (curPre + 1) % 10; ans = max(ans, solve(idx + 1, curPre) + cur); } } for (int i = 0; i < sz; i++) { for (int j = 0; j < sz; j++) { if (i == j || v[idx][i].first + v[idx][j].first >= 3) continue; for (int k = 0; k < sz; k++) { if (k == i || k == j || v[idx][i].first + v[idx][j].first + v[idx][k].first > 3) continue; long long cur = 0; long long curPre = pre; if (curPre == 0) cur += 2 * v[idx][i].second; else cur += v[idx][i].second; curPre = (curPre + 1) % 10; if (curPre == 0) cur += 2 * v[idx][j].second; else cur += v[idx][j].second; curPre = (curPre + 1) % 10; if (curPre == 0) cur += 2 * v[idx][k].second; else cur += v[idx][k].second; curPre = (curPre + 1) % 10; ans = max(ans, solve(idx + 1, curPre) + cur); } } } return ans; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { int k; cin >> k; vector<int> g[4]; for (int j = 0; j < k; j++) { int c, d; cin >> c >> d; g[c].push_back(d); } for (auto &x : g) sort(x.rbegin(), x.rend()); for (int j = 0; j < 3; j++) { if (j >= g[1].size()) break; v[i].push_back({1, g[1][j]}); } if (g[2].size() >= 1) v[i].push_back({2, g[2][0]}); if (g[3].size() >= 1) v[i].push_back({3, g[3][0]}); } memset(dp, -1, sizeof dp); cout << solve(0, 1); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<long long> carry(10, LONG_LONG_MIN); carry[0] = 0; for (int r = 0; r < n; r++) { int k; cin >> k; vector<vector<vector<long long>>> dp( 10, vector<vector<long long>>(3 + 1, vector<long long>(3, LONG_LONG_MIN))); for (int i = 0; i < 10; i++) { dp[i][0][0] = carry[i]; } for (int card = 0; card < k; card++) { int cost; long long dmg; cin >> cost >> dmg; for (int j = 3; j >= cost; j--) { dp[0][j][0] = max(dp[0][j][0], dp[9][j - cost][0] + 2 * dmg); dp[0][j][1] = max(dp[0][j][1], dp[9][j - cost][0] + dmg); dp[0][j][0] = max(dp[0][j][0], dp[9][j - cost][2] + dmg); for (int i = 1; i < 10; i++) { dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j - cost][0] + dmg); dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j - cost][1] + dmg); dp[i][j][2] = max(dp[i][j][2], dp[i - 1][j - cost][2] + dmg); dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j - cost][1] + 2 * dmg); dp[i][j][2] = max(dp[i][j][2], dp[i - 1][j - cost][0] + 2 * dmg); } } } carry.assign(10, LONG_LONG_MIN); for (int i = 0; i < 10; i++) { for (int j = 0; j < 3 + 1; j++) { carry[i] = max(carry[i], dp[i][j][0]); } } } long long result = 0; for (int i = 0; i < 10; i++) { result = max(result, carry[i]); } cout << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; vector<long long> v[3][200043]; long long dp[200043][12]; long long fun(int pos, int cnt) { if (pos == n) return 0; if (dp[pos][cnt] != -1) return dp[pos][cnt]; long long ans = fun(pos + 1, cnt); ans = max(ans, fun(pos + 1, (cnt + 1) % 10) + ((cnt == 9) ? 2 : 1) * v[0][pos][0]); ans = max(ans, fun(pos + 1, (cnt + 1) % 10) + ((cnt == 9) ? 2 : 1) * v[1][pos][0]); ans = max(ans, fun(pos + 1, (cnt + 1) % 10) + ((cnt == 9) ? 2 : 1) * v[2][pos][0]); ans = max(ans, fun(pos + 1, (cnt + 2) % 10) + ((cnt >= 8) ? 2 : 1) * v[0][pos][0] + v[0][pos][1]); ans = max(ans, fun(pos + 1, (cnt + 3) % 10) + ((cnt >= 7) ? 2 : 1) * v[0][pos][0] + v[0][pos][1] + v[0][pos][2]); long long mini = min(v[0][pos][0], v[1][pos][0]); long long maxi = max(v[0][pos][0], v[1][pos][0]); ans = max(ans, fun(pos + 1, (cnt + 2) % 10) + ((cnt >= 8) ? 2 : 1) * maxi + mini); return dp[pos][cnt] = ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) { int k; cin >> k; priority_queue<long long> c1; long long mini1 = -1e15; long long mini2 = -1e15; for (int l = 0; l < k; l++) { long long c, d; cin >> c >> d; if (c == 1) c1.push(d); else if (c == 2) mini1 = max(d, mini1); else mini2 = max(d, mini2); } int k1 = 0; while (k1 < 3 && !c1.empty()) { v[0][i].push_back(c1.top()); c1.pop(); k1++; } if (k1 < 3) { while (k1 < 3) { v[0][i].push_back(-1e15); k1++; } } v[1][i].push_back(mini1); v[2][i].push_back(mini2); } long long ans = fun(0, 0); cout << ans << endl; return 0; }