n, m, c = gets.split.map(&:to_i)
limits = gets.split.map(&:to_i)
balls = Array.new(c).map { [] }
n.times do
  color, value = gets.split.map(&:to_i)
  balls[color - 1] << value
end
balls.each.with_index do |a, i|
  a.sort!
  a.shift until a.size <= limits[i]
end
balls.flatten!
balls.sort!
p balls.size >= m ? balls[-m..-1].inject(:+) : balls.inject(:+)

