※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 17550번 문제인 Inquiry I이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/17550
17550번: Inquiry I
The Bureau for Artificial Problems in Competitions wants you to solve the following problem: Given
www.acmicpc.net
한편,
위의 관찰을 이용해 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long long ll;
int N, total; ll totals, mx;
int A[1000000];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
total += A[i];
}
for (int i = 0; i < N; i++) {
total -= A[i];
totals += A[i] * A[i];
mx = max(mx, totals * total);
}
cout << mx;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 17423 // C++] 민원이 넘쳐흘러 (0) | 2024.03.15 |
---|---|
[BOJ 9512 // C++] Languages (0) | 2024.03.14 |
[BOJ 31589 // C++] 포도주 시음 (2) | 2024.03.12 |
[BOJ 28117 // C++] prlong longf (0) | 2024.03.11 |
[BOJ 29704 // C++] 벼락치기 (0) | 2024.03.10 |