99
90
Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
90
40
Đây nha em
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << endl;
#define task ""
using namespace std;
int n, k; // k là số loại bi mà đề bài yêu cầu, n là số loại bi có
int a[10001], ans=0;
int main()
{
//freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i=1; i<=n; i++)
{
cin >> a[i];
}
sort (a+1, a+1+n); //xếp lại số bi từ nhỏ đến lớn
for (int i=n; i>=n-k+2; i--)
{
ans += a[i];
}
cout << ans+1;
#ifdef dungctb
cerr << "Time collapse : " << fixed << setprecision(3) << 1.000*clock()/CLOCKS_PER_SEC;
#endif // dungctb
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin
90
2638
40
vậy thì bài này chưa làm đc đâu :(
99
1528
90
int bagsAndMarbles(int[] arr, int n) { } ở đây là code cho java anh chỉ e cái nào cũng được ạ
90
2638
40
Nhập vào cái đó thì như này #include <bits/stdc++.h> #define debug(x) cerr << #x << " = " << x << endl; #define task "" using namespace std; int n, k; // k là số loại bi mà đề bài yêu cầu int a[10001], ans=0; int bagsAndMarbles(int arr[], int n) { sort (arr+1, arr+1+n); //xếp lại số bi từ nhỏ đến lớn for (int i=n; i>=n-k+2; i--) { ans += arr[i]; } cout << ans+1; } int main() { //freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> k; int tmp, i=0; while (cin >> tmp) { i++; cin >> tmp; a[i] = tmp; } cout << bagsAndMarbles(a, k); #ifdef dungctb cerr << "Time collapse : " << fixed << setprecision(3) << 1.000*clock()/CLOCKS_PER_SEC; #endif // dungctb return 0; } Rút gọnNhập vào cái đó thì như này #include <bits/stdc++.h> #define debug(x) cerr << #x << " = " << x << endl; #define task "" using namespace std; int n, k; // k là số loại bi mà đề bài yêu cầu int a[10001], ans=0; int bagsAndMarbles(int arr[], int n) { ... xem thêm
99
1528
90
điền vào { } mà anh
90
2638
40
ừ. điền vào { } là cái sort (arr+1, arr+1+n); //xếp lại số bi từ nhỏ đến lớn for (int i=n; i>=n-k+2; i--) { ans += arr[i]; } cout << ans+1; đó
99
1528
90
https://codelearn.io/fightstask/index?id=1544018&taskid=1532052 anh vào đây xem thử ạ =(
90
2638
40
Ủa đang thi sao lại hỏi thế này?
99
1528
90
e nghĩ mãi ko ra ạ =(((((((((((((((((((((((((((((