#美团笔试#
老哥们送外卖这个哪里错了,直接排序不行吗
public class Main {
   static class Pay {
      int vals;
      int weight;
      int id;

      public Pay(int vals, int weight, int id) {
         this.vals = vals;
         this.weight = weight;
         this.id = id;
      }

      int pay() {
         return vals + weight * 2;
      }
   }

   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt(), m = sc.nextInt();
      Pay[] pays = new Pay[n];
      for (int i = 0; i < n; i++) {
         pays[i] = new Pay(sc.nextInt(), sc.nextInt(), i);
      }
      Arrays.sort(pays, (p1, p2) -> {
         int t = p2.pay() - p1.pay();
         if (t == 0) {
            return p1.id - p2.id;
         }
         return t;
      });
      for (int i = 1; i < m; i++) {
         System.out.println((pays[i].id + 1) + " ");
      }
   }
}
全部评论
用剑指topK的方法,做到55,不知道漏了哪个情况
点赞 回复 分享
发布于 2020-08-22 22:51
我也是这样写的,很迷惑
点赞 回复 分享
发布于 2020-08-22 18:49

相关推荐

03-20 18:39
已编辑
电子科技大学 C++
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务