이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
#define pb push_back
#define vll vector<long long>
#define vb vector<bool>
#define vi vector<int>
#define vs vector<string>
#define vpii vector< pair<int, int> >
#define pii pair<int, int>
#define pbb pair<bool, bool>
#define pll pair<long long, long long>
#define vvi vector< vector<int> >
#define ld long double
#define mp make_pair
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;
const int MAXN = 5e5+5;
pair<ll, ll> in[MAXN];
// Solution O(n). Add the differences between sizes as negatives in the array. The rest is Kadane Algorithm. (Maximum contiguous sum)
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> in[i].first >> in[i].second;
sort(in, in + n);
reverse(in, in + n);
vector< ll > elems;
elems.pb(in[0].second);
for(int i = 1; i < n; i++)
{
if(in[i].first != in[i - 1].first)
elems.pb(in[i].first - in[i - 1].first);
elems.pb(in[i].second);
}
ll ans = 0, temp = 0;
for(int i = 0; i < elems.size(); i++)
{
temp += elems[i];
ans = max(ans, temp);
if(temp < 0)
temp = 0;
}
cout << ans << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
art.cpp: In function 'int main()':
art.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < elems.size(); i++)
| ~~^~~~~~~~~~~~~~
# | 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... |