using static System.Math; using System; public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var p = long.Parse(line[1]); var k = int.Parse(line[2]); var a = new int[n]; for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); if (line[0] == "1") a[i] = int.Parse(line[1]); } getAns(n, p, k, a); } static void getAns(int n, long p, int k, int[] a) { var MAX = (long)1e18; var HALF = MAX / 2; var dp = new long[n + 1, k + 1]; dp[0, 0] = p; for (int i = 0; i < n; i++) { for (int j = 0; j <= k; j++) { if (dp[i, j] > 0) { dp[i + 1, j] = Max(dp[i + 1, j], dp[i, j]); if (j == k) continue; if (a[i] > 0) { dp[i + 1, j + 1] = Max(dp[i + 1, j + 1], dp[i, j] + a[i]); if (dp[i + 1, j + 1] > MAX) { Console.WriteLine(-1); return; } } else { if (dp[i, j] > HALF) { Console.WriteLine(-1); return; } dp[i + 1, j + 1] = Max(dp[i + 1, j + 1], dp[i, j] * 2); } } } } Console.WriteLine(dp[n, k]); } }