이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> edge;
typedef pair<int, ll> pill;
typedef pair<pill, int> data;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
pll l[500000];
int n;
void solve() {
{
int k;
cin >> k;
vector<pll> v;
while(k--) {
ll a, b;
cin >> a >> b;
v.push_back({a, b});
}
sort(v.begin(), v.end());
for(int i = 0; i < v.size();) {
int j = i;
while(j < v.size() && v[i].first == v[j].first) {
l[n].second += v[j++].second;
}
l[n++].first = v[(i=j)-1].first;
}
}
ll ret = 0;
int lhs = 0;
ll sum = 0;
for(int i = 0; i < n; i++) {
ret = max(ret, l[i].second);
sum += l[i].second;
ret = max(ret, sum - (l[i].first - l[lhs].first));
if(sum <= l[i].first - l[lhs].first) {
lhs = i+1;
sum = 0;
}
while(lhs < i && sum - (l[i].first - l[lhs].first) <= (sum - l[lhs].second) - (l[i].first - l[lhs+1].first)) {
sum -= l[lhs++].second;
ret = max(ret, sum - (l[i].first - l[lhs].first));
}
}
cout << ret << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'void solve()':
art.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size();) {
~~^~~~~~~~~~
art.cpp:31:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j < v.size() && v[i].first == v[j].first) {
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |