728x90
반응형
1487 물건 팔기
문제 풀이
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void fast_io(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main(void)
{
fast_io();
long long n, max = 0, idx = 0;
vector<pair<int, int>> v;
cin >> n;
int arr[51];
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
v.push_back(make_pair(a, b));
}
sort(v.begin(), v.end());
int maxp = 0;
int tmaxp = 0;
for (int i = 0; i < n; i++)
{
int total = 0;
for (int j = i; j < n; j++)
{
int won = v[i].first - v[j].second;
if (won > 0)
total += won;
}
if (tmaxp < total)
{
tmaxp = total;
maxp = v[i].first;
}
}
cout << maxp;
}
배달비에대해서 착각을 하고있었다. 정렬도 필요하다..
728x90
반응형
'자라는 개발자 > 문제풀이' 카테고리의 다른 글
백준 c++ 17952 과제는 끝나지 않아! (1) | 2022.01.26 |
---|---|
백준 c++ 3986 좋은 단어 (0) | 2022.01.26 |
백준 c++ 1120 문자열 (0) | 2022.01.24 |
백준 C++ 1439 뒤집기 (0) | 2022.01.23 |
백준 c++ 21156 A Rank Problem (0) | 2022.01.21 |