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.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Data Structures
  3. Arrays
  4. Array Manipulation
  5. Discussions

Array Manipulation

Problem
Submissions
Leaderboard
Discussions
Editorial

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

  • acdevbox1 4 years ago+ 0 comments

    Same solution in C#

    using System;
    using System.Collections.Generic;
    using System.IO;
    class Solution {
        
        static void Main(String[] args) {
            
            string[] inString = Console.ReadLine().Split(' ');
            uint[] initParams = Array.ConvertAll(inString, UInt32.Parse);
            uint n = initParams[0];
            uint m = initParams[1];
            
            long[] numList = new long[n+1];
            
            for(int i=0; i<m; i++)
            {
                string[] opString = Console.ReadLine().Split(' ');
                uint a = UInt32.Parse(opString[0]);
                uint b = UInt32.Parse(opString[1]);
                long k = long.Parse(opString[2]);
                
                numList[a] += k;
                if(b+1 <= n) numList[b+1] -= k;
            }
            
            long tempMax = 0;
            long max = 0;
            for(int i=1; i<=n; i++)
            {
                tempMax += numList[i]; 
                if(tempMax > max) max = tempMax;
            }
            
            Console.WriteLine(max.ToString());
        }
    }
    
    7|
    ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature