解题思路:
注意事项:
参考代码:
import java.util.*; import java.math.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int m=sc.nextInt(); int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); } int count=0; Arrays.sort(arr); int first=0,last=n-1; while(first<last){ if(arr[first]+arr[last]<=m){ first++; last--; count++; } else{ last--; count++; } if(first==last){ count++; break; } } System.out.println(count); } }
0.0分
0 人评分
校门外的树 (C语言代码)浏览:961 |
【亲和数】 (C语言代码)浏览:503 |
简单的a+b (C语言代码)浏览:599 |
WU-C语言程序设计教程(第三版)课后习题11.11 (C++代码)(想学链表的可以看看)浏览:1357 |
【金明的预算方案】 (C++代码)浏览:940 |
【绝对值排序】 (C语言代码)浏览:821 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:677 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:476 |
1071题解浏览:493 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:613 |