We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Superman Celebrates Diwali
  5. Discussions

Superman Celebrates Diwali

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • TChalla
    2 years ago+ 0 comments

    Python solution

    n, h, hl = map(int, input().split())
    cnt = f = [[0 for _ in range(1901)] for _ in range(1900)]
    g = [0 for _ in range(1901)]
    for ctr in range(n):
        lis = list(map(int, input().split()))
        for j in range(1, len(lis)):
            cnt[ctr][lis[j]] += 1
    for ctr in range(n):
        f[ctr][h] = cnt[ctr][h]
        if f[ctr][h] > g[h]:
            g[h] = f[ctr][h]
    for j in range(h - 1, -1, -1):
        for i in range(n):
            tmp = 0
            if j + hl <= h:
                if g[j + hl] > tmp: 
                    tmp = g[j + hl]
            if f[i][j + 1] > tmp: 
                tmp = f[i][j + 1]
            f[i][j] = tmp + cnt[i][j]
            if f[i][j] > g[j]:
                g[j] = f[i][j]
    ans = 0
    for ctr in range(n):
        ans = max(ans, f[ctr][0])
    print(ans)
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy