Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms
      • 10
        Basic Dynamic Programming
      • 11
        Recursion
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
        Heap
      • 17
        Hashing
      • 18
        Graph Representation
      • 19
        BFS

  • Becoming an influencer

    You’ve been posting a lot of content on social media throughout the last several months. Now you’d like to analyze your most popular period. You’d like to know the maximum amount of views your content got during a period that doesn’t exceed a time interval of length t.

    Input

    The first line of the input contains two integers n (1 ≤ n ≤ ) - the number of content pieces posted and t (1 ≤ t ≤ ) - the maximum time interval you’d like to consider.
    The next n lines contain space-separated integers - the time posted and the views obtained from the post (1 ≤ ).

    Output

    The program should print the maximum sum of views that are within a time period not exceeding t.

    Examples

    Input
    Output
    4 5 10 1000 12 1500 6 2000 1 1100
    3100

    Explanation

    The last two - posted at times 1 and 6 would result in 2000 + 1100 views.
     

    Constraints

    Time limit: 2 seconds

    Memory limit: 512 MB

    Output limit: 1 MB

    To check your solution you need to sign in
    Sign in to continue