编程介的小学生 2017-04-22 16:26 采纳率: 20.5%
浏览 843
已采纳

Win the Bonus

There is a game with m bankers, each holding a string of integers of length 3 (note: an integer that has less than 3 digits has zeros filled to the left, e.g. 5 is considered as 005). Each banker assigns to his\her string some bonus or penalty points. As a player, you are supposed to select n digits from the set {0,1,2,3,4,5,6,7,8,9} to form your own integer string. If your string contains some of the bankers' strings, then you will gain or lose points accordingly. For example, if there are two bankers assigning 20 bonus points to 356 and 10 penalty points to 674 respectively, and your string is 035674, then since 356 and 674 both appear once in your string, the score you get will be 20-10=10. The player getting the most points wins the game. If there are more than one player getting the most points, the one with the smallest string number wins.
Now, suppose that Harry Potter gets to know all the bankers' secret strings and their assigned points by waving his magic wand, it is still not an easy task to win the game even with Hermione on his side. So he has come to you for help -- given the string length n, you may write a program to find the winning string.

Input
The input consists of several test cases.
The first line of each test case contains two integers m and n (1<=n<=10000), where m is the number of bankers and n is the required length of the player's string.
The following m lines contain m pairs of integers which are the banker's string and the points assigned to it.
You may assume that all the bankers' strings are distinct.

Output
For each test case you are supposed to output the winning string you find in a line. No extra spaces are allowed.

Sample Input:
2 5
356 20
674 -10

Sample Output:
00356

  • 写回答

1条回答 默认 最新

  • shen_wei 2017-04-27 07:30
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了