이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
bool operator< (ii a, ii b){
return a.first < b.first || (a.first == b.first && a.second < b.second);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, ans = -INF;
cin >> n >> m;
vector<ii> arr(n);
for(int i = 0; i < n; i++) cin >> arr[i].second >> arr[i].first;
sort(all(arr));
for(int i = 0; i < n; i++){
set<ii> data;
int sum = arr[i].second;
vector<ii> temp;
for(int j = 1; j <= i; j++) temp.pb({arr[i - j].second, arr[i - j].first});
sort(all(temp), greater<ii>());
for(int j = 0; j < temp.size(); j++){
if(data.size() >= m - 1){
sum -= data.begin()->second;
data.erase(data.begin());
}
data.insert({temp[j].second, temp[j].first});
sum += temp[j].first;
if(data.size() == m - 1){
ans = max(ans, sum - 2 * (arr[i].first - data.begin()->first));
}
}
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'int32_t main()':
cake3.cpp:30:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < temp.size(); j++){
~~^~~~~~~~~~~~~
cake3.cpp:31:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(data.size() >= m - 1){
~~~~~~~~~~~~^~~~~~~~
cake3.cpp:37:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(data.size() == m - 1){
~~~~~~~~~~~~^~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |