이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define int long long
#define ld long double
#define crash assert(69 == 420)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 2e5 + 20;
const int LOG = 20;
ar<int, 2> get(stack<int> &s){
int sum = 0;
int mn = 0;
while(sum <= 0 && s.size()){
sum += s.top();
s.pop();
mn = min(mn, sum);
}
if(sum <= 0)return {-1, -1};
return {mn, sum};
}
void reverse(stack<int> &s){
stack<int> v;
while(s.size()){
v.push(s.top());
s.pop();
}
s = v;
}
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
int n , s;
cin>>n>>s;
vector<stack<int> > v;
priority_queue<ar<int, 3> > pq;
for(int i = 0;i < n;i++){
int p, x;
cin>>p>>x;
if(p == 0)v.push_back(stack<int>());
v.back().push(x);
}
for(auto &u: v)reverse(u);
for(int i = 0;i < v.size();i++){
ar<int,2> a = get(v[i]);
if(a[0] == -1)continue;
pq.push({a[0], a[1], i});
}
while(1){
ar<int, 3> a = pq.top();
pq.pop();
if(s + a[0] < 0)break;
s += a[1];
ar<int,2> b = get(v[a[2]]);
if(b[0] != -1)pq.push({b[0], b[1], a[2]});
}
cout<<s;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:49:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::stack<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i = 0;i < v.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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |