AhmedAshraff

Untitled

Nov 23rd, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define boAshraf ios_base::sync_with_stdio(false); cin.tie(NULL);
  3. #define ll long long
  4. #define sz(s) (int)(s).size()
  5. #define all(s) (s).begin(),(s).end()
  6. using namespace std;
  7. void File();
  8. void sol();
  9. const int N=4e3+5,M=4e4+5;
  10. bool cheat[N][M];
  11. int dp[2][N];
  12. int main() {
  13.     boAshraf
  14.     File();
  15.     int t = 1;
  16. //    cin >> t;
  17.     while (t--) {
  18.         sol();
  19.     }
  20.     return 0;
  21. }
  22.  
  23. void sol() {
  24.     int n;
  25.     cin>>n;
  26.     for(int i=1;i<=n;i++){
  27.         int ss;
  28.         cin>>ss;
  29.         while(ss--){
  30.             int x;
  31.             cin>>x;
  32.             cheat[i][x]=true;
  33.         }
  34.     }
  35.     fill(dp[0],dp[0]+N,-1e5);
  36.     dp[0][0]=0;
  37.     int mx=0,tt=1,id=1;
  38.     for(int t=1;t<M;t++){
  39.         for(int c=1; c <= n; c++){
  40.             dp[id][c]=max({dp[1-id][c], dp[1 - id][c - 1],(c+1<=n?dp[1 - id][c + 1]:(int)-1e5)})+cheat[c][t];
  41.             if(dp[id][c]>mx)mx=dp[id][c],tt=t;
  42.         }
  43.         id^=1;
  44.     }
  45.     cout<<mx<<' '<<tt;
  46. }
  47.  
  48. void File() {
  49. #ifndef ONLINE_JUDGE
  50.     freopen("input.txt", "r", stdin);
  51.     freopen("output.txt", "w", stdout);
  52. #endif
  53. }
Advertisement
Add Comment
Please, Sign In to add comment