이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
int main() {
int n; cin >> n;
vector<pair<ll,int>> v(n);
for(auto& [a,b]: v) cin >> a >> b;
sort(all(v));
// Kadane's algorithm
ll ans = 0, cur = 0;
for(int i=0;i<n;++i) {
if(i) cur-=v[i].first-v[i-1].first;
if(cur<0) cur=0;
cur+=v[i].second;
ans = max(cur,ans);
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'int main()':
art.cpp:15:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
15 | for(auto& [a,b]: v) cin >> a >> b;
| ^
# | 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... |