Đăng nhập để hỏi chi tiết


Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[1005];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int max1=-1,max2=-1;
int ans=0;
int n;
cin>>n;
for(int i=1; i<=n; i++) {
cin>>a[i];
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
ans=max(ans,a[i]*a[i]+a[j]*a[j]);
}
}
cout<<ans;
}Hãy giúp mọi người biết câu trả lời này thế nào?
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
const long long nmax = 1e6 + 5;
long long a[nmax], n, mx = 0;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin >> n;
for (long long i = 1; i <= n; ++i) cin >> a[i];
for (long long i = 1; i <= n; ++i)
{
for (long long j = i + 1; j <= n; ++j)
{
mx = max(mx, a[i] * a[i] + a[j] * a[j]);
}
}
cout << mx;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin