File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using namespace std ;
4+ const int M = (int )10e7 ;
5+ int arr2[M];
6+ void merge (int arr[], int left,int mid,int right){
7+ int i = left;
8+ int j = mid+1 ;
9+ int k = left;
10+ while (i<=mid && j<=right){
11+ if (arr[i]>arr[j]){
12+ arr2[k] = arr[j];
13+ j++;
14+ }
15+ else { arr2[k] = arr[i];
16+ i++;
17+ }
18+ k++;
19+
20+ }
21+
22+ if (j>right){
23+ while (i<=mid){
24+ arr2[k] = arr[i];
25+ i++;
26+ k++;
27+ }
28+ }
29+ else {
30+ while (j<=right){
31+ arr2[k] = arr[j];
32+ k++;
33+ j++;
34+
35+ }
36+ }
37+
38+ for (int i= left; i<=right; i++){
39+ arr[i] = arr2[i];
40+ }
41+
42+ }
43+
44+ void mergeSort (int a[],int l,int r){
45+ if (l<r){
46+ int mid = (l+r)/2 ;
47+ mergeSort (a,l,mid);
48+ mergeSort (a,mid+1 ,r);
49+ merge (a,l,mid,r);
50+ }
51+ }
52+
53+
54+ int main () {
55+ // freopen("input.txt","r",stdin);
56+
57+ int n,m,cases=0 ;
58+ while (cin>>n>>m){
59+ cases++;
60+ if (n==0 && m==0 ) break ;
61+
62+ int arr[n];
63+ int arr3[m];
64+ for (int i=0 ; i<n; i++){
65+ cin>>arr[i];
66+ }
67+
68+ for (int j=0 ; j<m; j++){
69+ cin>>arr3[j];
70+ }
71+
72+ mergeSort (arr,0 ,n-1 );
73+ if (n<=m) cout<<" Case " <<cases<<" : " <<0 <<endl;
74+ else cout<<" Case " <<cases<<" : " <<n-m<<" " <<arr[0 ]<<endl;
75+ }
76+
77+ }
You can’t perform that action at this time.
0 commit comments