Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define boAshraf ios_base::sync_with_stdio(false); cin.tie(NULL);
- #define ll long long
- #define sz(s) (int)(s).size()
- #define all(s) (s).begin(),(s).end()
- using namespace std;
- void File();
- void sol();
- const int N=4e3+5,M=4e4+5;
- bool cheat[N][M];
- int dp[2][N];
- int main() {
- boAshraf
- File();
- int t = 1;
- // cin >> t;
- while (t--) {
- sol();
- }
- return 0;
- }
- void sol() {
- int n;
- cin>>n;
- for(int i=1;i<=n;i++){
- int ss;
- cin>>ss;
- while(ss--){
- int x;
- cin>>x;
- cheat[i][x]=true;
- }
- }
- fill(dp[0],dp[0]+N,-1e5);
- dp[0][0]=0;
- int mx=0,tt=1,id=1;
- for(int t=1;t<M;t++){
- for(int c=1; c <= n; c++){
- 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];
- if(dp[id][c]>mx)mx=dp[id][c],tt=t;
- }
- id^=1;
- }
- cout<<mx<<' '<<tt;
- }
- void File() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment