이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
using namespace std;
#define int ll
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
const int N = 5e5 + 11;
const ll INF2 = 2e18 + 11;
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
int n;
pii a[N];
main() {
cin>>n;
fo(i,1,n,1) cin>>a[i].F>>a[i].S;
sort(a+1,a+n+1, greater<pii>());
int r = 0,sum=0,ans=-2e18+11;
fo(l,1,n,1) {
if (r<l) r=l,sum=a[l].S;
while (r + 1 <= n) {
int val1=sum-a[l].F+a[r].F;
int val2=sum+a[r+1].S-a[l].F+a[r+1].F;
if (1) ++r,sum+=a[r].S;
else break;
chmax(ans,sum-a[l].F+a[r].F);
}
r=l;
}
cout<<ans;
return 0;
}
/**
15
1543361732 260774320
2089759661 257198921
1555665663 389548466
4133306295 296394520
2596448427 301103944
1701413087 274491541
2347488426 912791996
2133012079 444074242
2659886224 656957044
1345396764 259870638
2671164286 233246973
2791812672 585862344
2996614635 91065315
971304780 488995617
1523452673 988137562
*/
컴파일 시 표준 에러 (stderr) 메시지
art.cpp:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
art.cpp: In function 'int main()':
art.cpp:34:11: warning: unused variable 'val1' [-Wunused-variable]
int val1=sum-a[l].F+a[r].F;
^~~~
art.cpp:35:11: warning: unused variable 'val2' [-Wunused-variable]
int val2=sum+a[r+1].S-a[l].F+a[r+1].F;
^~~~
# | 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... |