Submission #37468803
				
			
			
			Source Code Expand
			#!/usr/bin/env stack
{- stack script --resolver lts-16.11
--package array --package bytestring --package containers
--package vector --package vector-algorithms --package primitive --package transformers
-}
{- ORMOLU_DISABLE -}
{-# LANGUAGE BangPatterns, BlockArguments, LambdaCase, MultiWayIf, PatternGuards, TupleSections #-}
{-# LANGUAGE NumDecimals, NumericUnderscores #-}
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables, TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{- ORMOLU_ENABLE -}
-- {{{ Imports
module Main (main) where
import Control.Monad
import Control.Monad.ST
import Data.Char
import Data.List
{- ORMOLU_DISABLE -}
-- array
import Data.Array.IArray
import Data.Array.IO
import Data.Array.MArray
import Data.Array.ST
import Data.Array.Unsafe
-- import qualified Data.Array as A
import Data.Array.Unboxed (UArray)
-- bytestring: https://www.stackage.org/lts-16.11/package/bytestring-0.10.10.0
import qualified Data.ByteString.Char8 as BS
-- vector: https://www.stackage.org/lts-16.11/package/vector-0.12.1.2
import qualified Data.Vector.Unboxed as VU
import qualified Data.Map.Strict as M
{- ORMOLU_ENABLE -}
getLineIntList :: IO [Int]
getLineIntList = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
getLineIntVec :: IO (VU.Vector Int)
getLineIntVec = VU.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
-- TODO: use type parameter `e`
{-# INLINE tabulateMap #-}
tabulateMap :: forall i e. (Ix i) => (M.Map i e -> i -> e) -> (i, i) -> M.Map i e -> M.Map i e
tabulateMap f bounds_ cache0 =
  foldl' step cache0 (range bounds_)
  where
    step :: M.Map i e -> i -> M.Map i e
    step cache i =
      let e = f cache i
       in M.insert i e cache
main :: IO ()
main = do
  [nItems, wLimit] <- getLineIntList
  wvs <- VU.replicateM nItems $ (\[a, b] -> (a, b)) <$> getLineIntList
  let dp = tabulateMap f bounds_ M.empty
      bounds_ = ((0, 0), (nItems, wLimit))
      f :: M.Map (Int, Int) Int -> (Int, Int) -> Int
      f _ (0, _) = 0
      f cache (i, w) =
        let wv = wvs VU.! (i - 1)
            v1 = cache M.! (i - 1, w)
            v2 =
              if w - fst wv >= 0
                then (snd wv +) $ cache M.! (i - 1, w - fst wv)
                else 0
         in max v1 v2
  print $ maximum [dp M.! (nItems, w) | w <- [0 .. wLimit]]
			
				Submission Info
				
			
			
			
				
					| Submission Time | 
					 | 
				
				
					| Task | 
					A19 - Knapsack 1 | 
				
				
					| User | 
					toyboot4e  | 
				
				
					| Language | 
					Haskell (GHC 8.8.3) | 
				
				
					| Score | 
					0 | 
				
				
					| Code Size | 
					2397 Byte | 
				
				
					| Status | 
					TLE | 
				
				
					
						| Exec Time | 
						10255 ms | 
					
					
						| Memory | 
						1218848 KiB | 
					
				
			
 
			
				Compile Error
				Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default
			
			
				Judge Result
				
					
							
								| Set Name | 
								
									Sample | 
								
									All | 
								
							
							
								| Score / Max Score | 
								
									0 / 0 | 
								
									0 / 1000 | 
								
							
							
								| Status | 
								
									
										
											
											
										
									 | 
								
									
										
											
											
										
									 | 
								
							
						
 
				 
				
					
						
						
							| Set Name | 
							Test Cases | 
						
						
						
						
							
								| Sample | 
								sample_01.txt, sample_02.txt, sample_03.txt | 
							
						
							
								| All | 
								in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, sample_01.txt, sample_02.txt, sample_03.txt | 
							
						
						
					
 
					
						
							
							
								| Case Name | 
								Status | 
								Exec Time | 
								Memory | 
							
							
							
							
							
								| in01.txt | 
								
									AC | 
									169 ms | 
									41356 KiB | 
								
							
							
							
								| in02.txt | 
								
									AC | 
									948 ms | 
									158136 KiB | 
								
							
							
							
								| in03.txt | 
								
									AC | 
									975 ms | 
									158196 KiB | 
								
							
							
							
								| in04.txt | 
								
									AC | 
									966 ms | 
									158292 KiB | 
								
							
							
							
								| in05.txt | 
								
									AC | 
									959 ms | 
									158064 KiB | 
								
							
							
							
								| in06.txt | 
								
									AC | 
									921 ms | 
									158176 KiB | 
								
							
							
							
								| in07.txt | 
								
									MLE | 
									9835 ms | 
									1184340 KiB | 
								
							
							
							
								| in08.txt | 
								
									MLE | 
									9849 ms | 
									1205688 KiB | 
								
							
							
							
								| in09.txt | 
								
									MLE | 
									9883 ms | 
									1203676 KiB | 
								
							
							
							
								| in10.txt | 
								
									MLE | 
									9866 ms | 
									1203648 KiB | 
								
							
							
							
								| in11.txt | 
								
									MLE | 
									9897 ms | 
									1203700 KiB | 
								
							
							
							
								| in12.txt | 
								
									TLE | 
									10196 ms | 
									1192392 KiB | 
								
							
							
							
								| in13.txt | 
								
									TLE | 
									10223 ms | 
									1212976 KiB | 
								
							
							
							
								| in14.txt | 
								
									TLE | 
									10190 ms | 
									1194468 KiB | 
								
							
							
							
								| in15.txt | 
								
									TLE | 
									10250 ms | 
									1218848 KiB | 
								
							
							
							
								| in16.txt | 
								
									TLE | 
									10255 ms | 
									1215944 KiB | 
								
							
							
							
								| in17.txt | 
								
									AC | 
									998 ms | 
									158048 KiB | 
								
							
							
							
								| in18.txt | 
								
									AC | 
									977 ms | 
									158048 KiB | 
								
							
							
							
								| in19.txt | 
								
									AC | 
									948 ms | 
									158168 KiB | 
								
							
							
							
								| in20.txt | 
								
									MLE | 
									9958 ms | 
									1184292 KiB | 
								
							
							
							
								| in21.txt | 
								
									MLE | 
									9935 ms | 
									1204676 KiB | 
								
							
							
							
								| in22.txt | 
								
									TLE | 
									10039 ms | 
									1187284 KiB | 
								
							
							
							
								| sample_01.txt | 
								
									AC | 
									8 ms | 
									3680 KiB | 
								
							
							
							
								| sample_02.txt | 
								
									AC | 
									3 ms | 
									3908 KiB | 
								
							
							
							
								| sample_03.txt | 
								
									AC | 
									7 ms | 
									5108 KiB |