malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF32 = 0x3f3f3f3f;   const double EPS = 1.0e-8;   const double PI = acos(-1.0);   struct Point {     double x, y;     Point(double _x = 0, double _y = 0) {       x = _x;       y = _y;     }     friend Point operator+(const Point &a, const Point &b) {       return Point(a.x + b.x, a.y + b.y);     }     friend Point operator-(const Point &a, const Point &b) {       return Point(a.x - b.x, a.y - b.y);     }     friend double operator^(const Point &a, const Point &b) {       return a.x * b.y - a.y * b.x;     }     friend bool operator==(const Point &a, const Point &b) {       return fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS;     }   };   struct V {     Point start, end;     V(Point _start = Point(0, 0), Point _end = Point(0, 0)) {       start = _start;       end = _end;     }   };   Point Basic;   set<Point> Set;   double Distance(Point a, Point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   bool operator<(Point a, Point b) {     a = a - Basic;     b = b - Basic;     double Ang1 = atan2(a.y, a.x), Ang2 = atan2(b.y, b.x);     double Len1 = Distance(a, Point(0.0, 0.0)),            Len2 = Distance(b, Point(0.0, 0.0));     if (fabs(Ang1 - Ang2) < EPS) return Len1 < Len2;     return Ang1 < Ang2;   }   set<Point>::iterator Pre(set<Point>::iterator it) {     if (it == Set.begin()) it = Set.end();     return --it;   }   set<Point>::iterator Nxt(set<Point>::iterator it) {     ++it;     return it == Set.end() ? Set.begin() : it;   }   int Query(Point p) {     set<Point>::iterator it = Set.lower_bound(p);     if (it == Set.end()) it = Set.begin();     return ((p - *(Pre(it))) ^ (*(it) - *(Pre(it)))) < EPS;   }   void Insert(Point p) {     if (Query(p)) return;     Set.insert(p);     set<Point>::iterator it = Nxt(Set.find(p));     while (Set.size() > 3 && ((p - *(Nxt(it))) ^ (*(it) - *(Nxt(it)))) < EPS) {       Set.erase(it);       it = Nxt(Set.find(p));     }     it = Pre(Set.find(p));     while (Set.size() > 3 && ((p - *(it)) ^ (*(it) - *(Pre(it)))) > -EPS) {       Set.erase(it);       it = Pre(Set.find(p));     }   }   int main() {     int q;     scanf( %d , &q);     Basic = Point(0, 0);     int oper;     Point a, str[5];     for (int i = 1; i <= 3; ++i) {       scanf( %d%lf%lf , &oper, &str[i].x, &str[i].y);       Basic = Basic + str[i];     }     Basic.x /= 3.0;     Basic.y /= 3.0;     q -= 3;     for (int i = 1; i <= 3; ++i) {       Set.insert(str[i]);     }     while (q--) {       scanf( %d%lf%lf , &oper, &a.x, &a.y);       if (oper == 1) {         Insert(a);       } else {         if (Query(a))           printf( YES n );         else           printf( NO n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<array<int, 2>> v, good;   long long f(int x, int y) {     return abs(v[x][0] - v[y][0]) + abs(v[x][1] - v[y][1]);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n;     v.resize(n);     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> v[i][0] >> v[i][1];     }     int min_x = -1, max_x = -1, min_y = -1, max_y = -1;     for (int i = 0; i < n; i++) {       if (min_x == -1 || v[i][0] < v[min_x][0]) {         min_x = i;       }       if (max_x == -1 || v[i][0] > v[max_x][0]) {         max_x = i;       }       if (min_y == -1 || v[i][1] < v[min_y][1]) {         min_y = i;       }       if (max_y == -1 || v[i][1] > v[max_y][1]) {         max_y = i;       }       ans += f(i, (i + 1) % n);     }     if (n == 3) {       return cout << ans, 0;     }     set<int> st;     st.insert(min_x), st.insert(max_x), st.insert(min_y), st.insert(max_y);     for (int i : st) good.push_back(v[i]);     long long ans3 = 0;     if ((int)(good).size() < 4) {       ans3 = ans;     } else {       for (int i = 0; i < n; i++) {         for (int j = 0; j < 4; j++) {           for (int k = j + 1; k < 4; k++) {             long long cur = 0;             cur += abs(good[j][0] - v[i][0]) + abs(good[j][1] - v[i][1]);             cur += abs(good[j][0] - good[k][0]) + abs(good[j][1] - good[k][1]);             cur += abs(good[k][0] - v[i][0]) + abs(good[k][1] - v[i][1]);             ans3 = max(ans3, cur);           }         }       }     }     cout << ans3 <<    ;     for (int i = 4; i <= n; i++) {       cout << ans <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long base = 7;   const long long maxn = 1e6 + 9;   const long long inf = 1e9 + 7;   queue<long long> l[30], r[30], l1, r1, lf, rf;   vector<pair<long long, long long> > res;   long long n, i;   string a, b;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> a >> b;     a =     + a;     b =     + b;     for (i = 1; i <= n; i++) {       if (a[i] !=  ? )         l[a[i] -  a ].push(i);       else         l1.push(i);     }     for (i = 1; i <= n; i++) {       if (b[i] !=  ? )         r[b[i] -  a ].push(i);       else         r1.push(i);     }     for (i = 0; i <= 27; i++) {       while (true) {         if (!l[i].empty() && !r[i].empty()) {           res.push_back(make_pair(l[i].front(), r[i].front()));           l[i].pop();           r[i].pop();         } else {           while (!l[i].empty()) {             lf.push(l[i].front());             l[i].pop();           }           while (!r[i].empty()) {             rf.push(r[i].front());             r[i].pop();           }           break;         }       }     }     while (true) {       if (!lf.empty() && !r1.empty()) {         res.push_back(make_pair(lf.front(), r1.front()));         lf.pop();         r1.pop();       } else         break;     }     while (true) {       if (!rf.empty() && !l1.empty()) {         res.push_back(make_pair(l1.front(), rf.front()));         rf.pop();         l1.pop();       } else         break;     }     while (true) {       if (!r1.empty() && !l1.empty()) {         res.push_back(make_pair(l1.front(), r1.front()));         r1.pop();         l1.pop();       } else         break;     }     cout << res.size() <<   n ;     for (i = 0; i < res.size(); i++)       cout << res[i].first <<     << res[i].second <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(false);     int ans, cnt, k;     string str;     while (cin >> str >> k) {       ans = 0;       cnt = 0;       int len = str.length();       for (int i = len - 1; i >= 0; i--) {         if (str[i] ==  0 ) {           ans++;         }       }       if (ans < k) {         cout << len - 1 << endl;       } else {         for (int i = len - 1; i >= 0; i--) {           if (str[i] !=  0 ) {             cnt++;           } else {             k--;           }           if (k == 0) {             break;           }         }         cout << cnt << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int b, d, ans, l, h;   char a[105], c[105];   bool letter[30];   int lena, lenc;   int ll[105], yy[105];   char aa[105 * 105];   inline int ok() {     memset(letter, 0, sizeof(letter));     for (char *p = a; *p; ++p) letter[*p -  a ] = 1;     for (char *p = c; *p; ++p)       if (letter[*p -  a ] == 0) return 0;     return 1;   }   inline int init() {     for (int i = 0; i < 105; ++i) strcpy(aa + i * lena, a);     for (int i = 0; i < lena; ++i) {       char *p = aa + i, *q = c;       while (*p && *q) {         while (*p && *p != *q) ++p;         if (*p != *q) return 0;         ++p, ++q;       }       if (*q != 0) return 0;       ll[i] = p - (aa + i);       yy[i] = (p - aa) % lena;     }     return 1;   }   inline int test(int p) {     p = p * d;     long long pos = 0;     long long vst[105], cnt[105];     memset(vst, -1, sizeof(vst));     for (int i = 0; i < p; ++i) {       if (pos >= lena * b) return 0;       if (vst[pos % lena] > -1) {         long long tmp = pos - vst[pos % lena];         long long tem = i - cnt[pos % lena];         pos += tmp * ((p - i) / tem);         i = (p - i) / tem * tem + i - 1;         memset(vst, -1, sizeof(vst));         continue;       }       if (i) {         vst[pos % lena] = pos;         cnt[pos % lena] = i;       }       pos += ll[pos % lena];     }     if (pos - 1 >= lena * b) return 0;     return 1;   }   int main(int argc, char **argv) {     scanf( %d%d , &b, &d);     scanf( %s%s , a, c);     lena = strlen(a), lenc = strlen(c);     if (!ok() || !init())       puts( 0 );     else {       ans = 0, l = 1, h = lena * b / (lenc * d);       while (l <= h) {         int mid = (l + h) >> 1;         if (test(mid))           ans = mid, l = mid + 1;         else           h = mid - 1;       }       printf( %d n , ans);     }     return 0;   }
#include<bits/stdc++.h>   #define pb push_back   #define mk make_pair   #define ll long long   #define ss second   #define ff first   #define pll pair<ll,ll>   #define vll vector<ll>   #define mll map<ll,ll>   #define mod 1000000007   #define w(x) ll x; cin>>x; while(x--)   #define ps(x,y) fixed<<setprecision(y)<<x;   #define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)   #define re(i, j) fo(i, 0, j, 1)   #define pi 3.1415926535897932384626433832795   #define all(cont) cont.begin(), cont.end()   #define countbit(x) __builtin_popcount(x)   #define mod 1000000007   #define lo lower_bound   #define de(n) ll n;cin>>n;   #define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}   #define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}   #define deb(x) cout<<#x<< = <<x<<endl;   #define tr(it,a) for(auto it=a.begin();it!=a.end();it++)   #define nl cout<<endl;      using namespace std;            int main()   {   ios_base::sync_with_stdio(0);   cin.tie(0);                  int n;           cin>>n;           int x[2]={1,-1};              int y[2]={1,-1};           pair<int,int> p;           p.first=0;           p.second=0;           int a1=n/2;           int a2=n-n/2;           if(n%2!=0){               int c=a2+1;               int d=(a1+1);               ll ans=1ll*2*(c*d);               cout<<ans<<endl;           }           else{               int c=a2+1;               int d=a1+1;               ll ans=1ll*c*d;               cout<<ans<<endl;           }                                                                       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   const int MAXV = 100010;   const int MAXT = 333;   int a[MAXN], n;   int b[MAXN], m;   int s, e;   vector<int> ind[MAXV];   int p[MAXN][MAXT];   int main() {     scanf( %d%d%d%d , &n, &m, &s, &e);     for (int i = int(0); i <= int((MAXV)-1); ++i) ind[i].clear();     for (int i = int(1); i <= int(n); ++i)       scanf( %d , a + i), ind[a[i]].push_back(i);     for (int i = int(1); i <= int(m); ++i) scanf( %d , b + i);     int mt = s / e;     int ans = 0;     for (int t = int(1); t <= int(mt); ++t) p[0][t] = n + 1;     p[0][0] = 0;     for (int j = int(1); j <= int(m); ++j) {       for (int t = int(0); t <= int(mt); ++t) p[j][t] = p[j - 1][t];       for (int t = int(0); t <= int(mt - 1); ++t) {         vector<int>::iterator it =             lower_bound(ind[b[j]].begin(), ind[b[j]].end(), p[j - 1][t] + 1);         if (it != ind[b[j]].end()) p[j][t + 1] = min(p[j][t + 1], *it);       }       for (int t = int(1); t <= int(mt); ++t) {         int i = p[j][t];         if (i > n) break;         int rest = s - (i + j);         int cnt = rest / e;         ans = max(ans, min(cnt, t));       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct rec {     int x, y;   } p;   char a[2][100010];   queue<rec> q;   int d[2][100010], n, k;   bool bfs() {     memset(d, -1, sizeof(d));     q.push((rec){0, 1});     d[0][1] = 0;     while (q.size()) {       p = q.front();       q.pop();       if (p.y + k > n) return 1;       if (a[p.x][p.y + 1] ==  -  && d[p.x][p.y + 1] == -1 &&           d[p.x][p.y] + 1 < p.y + 1)         q.push((rec){p.x, p.y + 1}), d[p.x][p.y + 1] = d[p.x][p.y] + 1;       if (a[p.x][p.y - 1] ==  -  && d[p.x][p.y - 1] == -1 &&           d[p.x][p.y] + 1 < p.y - 1)         q.push((rec){p.x, p.y - 1}), d[p.x][p.y - 1] = d[p.x][p.y] + 1;       if (a[p.x ^ 1][p.y + k] ==  -  && d[p.x ^ 1][p.y + k] == -1 &&           d[p.x][p.y] + 1 < p.y + k)         q.push((rec){p.x ^ 1, p.y + k}), d[p.x ^ 1][p.y + k] = d[p.x][p.y] + 1;     }     return 0;   }   int main() {     cin >> n >> k;     scanf( %s%s , a[0] + 1, a[1] + 1);     if (bfs())       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int Tea;     int Index;     friend bool operator<(const node& a, const node& b) { return a.Tea > b.Tea; }   } D[105];   int main() {     int i, n, w, Ans[105];     scanf( %d%d , &n, &w);     for (i = 0; i < n; i++) {       scanf( %d , &D[i].Tea);       D[i].Index = i;     }     sort(D, D + n);     int Judge = 0;     for (i = 0; i < n; i++) Judge += (D[i].Tea + 1) / 2;     if (Judge > w)       printf( -1 n );     else {       w -= Judge;       for (i = 0; i < n; i++) Ans[D[i].Index] = (D[i].Tea + 1) / 2;       for (i = 0; i < n && w; i++) {         if (w >= D[i].Tea - Ans[D[i].Index])           w -= D[i].Tea - Ans[D[i].Index], Ans[D[i].Index] = D[i].Tea;         else           Ans[D[i].Index] += w, w = 0;       }       for (i = 0; i < n; i++) {         if (i) printf(   );         printf( %d , Ans[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>      using namespace std;      #define y1 temp_y1   #define all(x) x.begin(), x.end()      const int N = 3e5 + 5;      int n;      int lst[N];   int fa[N];      vector<int> g[N];      int min_leaf = -1;   int ext_cnt = 0;   bool ok = true;      void dfs1(int u, int k) {     for (auto v : g[u]) {       dfs1(v, k);     }     if (ext_cnt < k && lst[u] != ext_cnt) {       ok = false;     }     if (ext_cnt == k) {       min_leaf = u;     }     ++ext_cnt;   }   long long ans = 0;   int seq[N];   int dfs_cnt = 0;   int siz[N];      void dfs2(int u, int k, int dep) {     seq[u] = dfs_cnt++;     if (lst[u] < k) {       ans += dep;       siz[u]++;     }      for (auto v : g[u]) {       dfs2(v, k, dep + 1);       siz[u] += siz[v];     }     if (lst[u] < k && lst[u] != ext_cnt) {       ok = false;     }     if (lst[u] >= k && siz[u] + seq[u] != lst[u]) {       ok = false;     }     ++ext_cnt;   }      int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> lst[i];       --lst[i];     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       --u;       --v;       fa[v] = u;       g[u].push_back(v);     }     for (int i = 0; i < n; ++i) {       sort(all(g[i]), [&](int x, int y) -> bool {         return lst[x] < lst[y];       });     }          if (lst[0] == 0) {       dfs2(0, 0, 0);       if (ok) {         cout <<  YES  << endl;         cout << 0 << endl;         for (int i = 0; i < n; ++i) {    cout << lst[i] + 1 <<    ;         }         cout << endl;         return 0;       } else {         cout <<  NO  << endl;         return 0;       }     }     int v = lst[0] - 1;     dfs1(0, v);     int u = min_leaf;     bool is_find = false;     fa[0] = -1;     //cerr << v + 1 <<     << u + 1 <<     << lst[u] + 1 <<endl;     do {       if (lst[u] == v) {         is_find = true;       }       if (lst[u] == v && fa[u] != -1) {         swap(lst[u], lst[fa[u]]);         ++ans;       }       u = fa[u];     } while (u != -1);     if (!is_find) {       cout <<  NO  << endl;       return 0;     }     ext_cnt = 0;     dfs2(0, v, 0);        if (ok) {       cout <<  YES  << endl;       cout << ans << endl;       for (int i = 0; i < n; ++i) {         cout << seq[i] + 1 <<     ;       }       cout << endl;     } else {       cout <<  NO  << endl;     }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int>> flowers;   vector<int> first_flowers;   vector<long long> pref_sum;   long long answer;   void In() {     flowers.clear();     pref_sum.clear();     first_flowers.clear();     answer = LLONG_MIN;     cin >> n >> m;     flowers.resize(m);     for (int i = 0; i < m; i++) cin >> flowers[i].first >> flowers[i].second;   }   long long GetPrefSum(int start_index) {     return pref_sum.back() -            ((start_index - 1 >= 0) ? pref_sum[start_index - 1] : 0);   }   void Try(int index) {     auto range = equal_range(first_flowers.begin(), first_flowers.end(),                              flowers[index].second);     int less_or_equal = range.second - first_flowers.begin();     int remaining = m - less_or_equal;     remaining = min(remaining, n);     int start_index = m - remaining;     if (index >= start_index) {       long long result = GetPrefSum(start_index);       long long left_take = n - remaining;       result += left_take * flowers[index].second;       answer = max(answer, result);     } else {       long long result = flowers[index].first;       int really_remaining = m - less_or_equal;       really_remaining = min(really_remaining, n - 1);       start_index = m - really_remaining;       result += GetPrefSum(start_index);       long long left_take = n - 1 - really_remaining;       result += left_take * flowers[index].second;       answer = max(answer, result);     }   }   void Solve() {     sort(flowers.begin(), flowers.end());     pref_sum.resize(m);     pref_sum[0] = flowers[0].first;     for (int i = 1; i < m; i++) pref_sum[i] = flowers[i].first + pref_sum[i - 1];     first_flowers.resize(m);     for (int i = 0; i < m; i++) first_flowers[i] = flowers[i].first;     for (int i = 0; i < m; i++) Try(i);   }   void Out() { cout << answer <<   n ; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       In();       Solve();       Out();     }   }
#include <bits/stdc++.h>   using namespace std;   int digit(long long int n) {     if (n > 0) return (digit(n / 10) + 1);     return 0;   }   int main() {     long long int l, h;     long long int a[] = {0,      4,       49,       499,       4999,      49999,                          499999, 4999999, 49999999, 499999999, 4999999999};     long long int b[] = {0,      9,       99,       999,       9999,      99999,                          999999, 9999999, 99999999, 999999999, 9999999999};     cin >> l >> h;     long long int ans = max(a[digit(l)], l);     ans = min(a[digit(h)], h);     ans = max(ans, l);     ans = (long long int)(ans) * (b[digit(ans)] - ans);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mo = 1e9 + 7;   int main() {     long long a, b, n;     while (cin >> a >> b) {       n = b - 1;       long long ans = 0;       for (int k = 1; k <= a; ++k) {         ans = (ans + (((((k * b) % mo) * ((n * (n + 1) / 2) % mo)) % mo +                        (n * (n + 1) / 2) % mo)) %                          mo) %               mo;       }       cout << ans % mo << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 110;   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(false);     int al, ar, bl, br;     cin >> al >> ar >> bl >> br;     if ((al * 2 + 3 > br && br >= al - 1) || (ar * 2 + 3 > bl && bl >= ar - 1))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int c = 0;   void bfs(map<long long int, vector<long long int> > &map, vector<bool> &visited,            long long int x) {     queue<long long int> q;     q.push(x);     visited[x] = true;     while (!q.empty()) {       long long int y = q.front();       q.pop();       for (long long int i : map[y]) {         if (!visited[i]) {           q.push(i);           visited[i] = true;         }       }     }   }   int main() {     long long int x, y, n, m;     cin >> n >> m;     map<long long int, vector<long long int> > map;     std::vector<bool> visited(n + 1, false), visitedf(n + 1, false);     for (long long int i = 0; i < m; i++) {       cin >> x >> y;       map[x].push_back(y);       map[y].push_back(x);     }     if (m != n - 1) {       cout <<  no ;       return 0;     }     bfs(map, visited, map.begin()->first);     for (long long int i = 1; i <= n; i++) {       if (!visited[i]) {         cout <<  no ;         return 0;       }     }     cout <<  yes ;   }
#include <bits/stdc++.h>   using namespace std;   bool custom(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first) {       return a.second < b.second;     }     return a.first < b.first;   }   bool c1(string a) {     int dec = 0;     for (int i = 0; i < a.size() - 1; i++) {       if (a[i] >= a[i + 1]) {         dec += (a[i] > a[i + 1]);       } else {         dec = 0;       }       if (dec == 2) {         return true;       }     }     return false;   }   bool c2(string b) {     char ant = b[0];     for (auto& first : b) {       if (ant > first) {         return true;       }       ant = first;     }     return false;   }   int main() {     int k;     cin >> k;     int i = 1;     string first = to_string(i);     while (k > first.size()) {       k -= first.size();       i++;       first = to_string(i);     }     int c = 0;     char an = first[0];     while (k > 0) {       an = first[c];       c++;       k--;     }     cout << an;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   vector<vector<int> > adj;   vector<int> col;   queue<int> x, y;   void colorear(int u, int c) {     col[u] = c;     for (int v : adj[u])       if (col[v] == -1) colorear(v, 1 - c);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     adj = vector<vector<int> >(2 * n + 2);     for (int i = 0; i < n; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);       x.push(a);       y.push(b);       if (a % 2) {         adj[a].push_back(a + 1);         adj[a + 1].push_back(a);       }       if (b % 2) {         adj[b].push_back(b + 1);         adj[b + 1].push_back(b);       }     }     col = vector<int>(2 * n + 2, -1);     for (int i = 1; i <= 2 * n; i++) {       if (col[i] == -1) {         colorear(i, 0);       }     }     while (n--) {       cout << col[x.front()] + 1 <<     << col[y.front()] + 1 <<   n ;       x.pop();       y.pop();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[100000];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int go;       cin >> go;       a[i].first = go;       a[i].second = i;     }     sort(a, a + n);     int an = 0;     for (int i = 0; i < n; i++) {       k -= a[i].first;       if (k < 0) break;       an++;     }     cout << an << endl;     for (int i = 0; i < an; i++) {       cout << a[i].second + 1 <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Day = 86400;   const long long INF = 1e18;   const int N = 4004;   long long dp[N][N], t[N], d[N];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int(i) = 0; (i) < (n); (i)++) scanf( %d%d , &t[i], &d[i]), t[i]--;     if (n == k) return printf( %d n , Day) & 0;     memset(dp, INF, sizeof dp);     dp[0][0] = 0;     for (int(i) = (1); (i) <= (n); (i)++)       for (int(j) = (0); (j) <= (k); (j)++)         if (j <= i) {           long long last = dp[i - 1][j];           if (last != INF) {             dp[i][j] = max(last, t[i - 1]) + d[i - 1];           }           if (j > 0) dp[i][j] = min(dp[i - 1][j - 1], dp[i][j]);         }     long long ans = 0;     for (int(left) = (0); (left) <= (n); (left)++) {       int right = min(k, left);       long long start = dp[left][right];       long long finish = left < n ? t[left] : Day;       if (start >= Day || finish > Day || start >= finish) continue;       ans = max(ans, finish - start);     }     printf( %I64d n , ans);     return 0;   }