This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unistd.h>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, int> pil;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
const int SS = 2007;
class Solution{
public:
ll N, S, xi, pi, res = 0;
vector<ll> profits = {-1};
ll profitProfit(){
cin >> N >> S;
for (int i = 1; i <= N; i++){
cin >> xi >> pi;
profits.push_back( xi );
}
if (pi == 0){
for (int i = 1; i <= N; i++){
res += max(0LL, profits[i]);
}
}
else {
ll maxS = S;
for (int i = 1; i <= N; i++){
S += profits[i]; maxS = max(maxS, S);
if (S < 0) break;
}
res = maxS - S;
}
return res;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
Solution p;
cout << p.profitProfit();
}
# | 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... |