Submission #870845

# Submission time Handle Problem Language Result Execution time Memory
870845 2023-11-09T09:47:57 Z pcc Discharging (NOI20_discharging) C++14
20 / 100
88 ms 10068 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


vector<pll> v;
vector<pll> st;
int n;
ll total = 0;
ll sum = 0;

inline bool check(pll a,pll b){
	ll ta = a.fs*a.sc+b.sc*(a.fs+b.fs);
	ll tb = b.fs*(a.sc+b.sc);
	if(ta>=tb)return true;
	else return false;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i = 0;i<n;i++){
		int k;
		cin>>k;
		if(v.empty()||v.back().fs < k)v.push_back({k,1});
		else v.back().sc++;
	}
	for(auto &i:v){
		while(!st.empty()&&check(st.back(),i)){
			total -= sum*st.back().sc;
			sum -= st.back().fs;
			i.sc+=st.back().sc;
			st.pop_back();
		}
		sum += i.fs;
		total += sum*i.sc;
		st.push_back(i);
	}
	cout<<total;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 79 ms 9908 KB Output is correct
2 Correct 73 ms 10064 KB Output is correct
3 Correct 73 ms 9900 KB Output is correct
4 Correct 73 ms 10064 KB Output is correct
5 Correct 75 ms 10064 KB Output is correct
6 Correct 74 ms 9916 KB Output is correct
7 Correct 88 ms 10064 KB Output is correct
8 Correct 74 ms 10064 KB Output is correct
9 Correct 72 ms 10068 KB Output is correct
10 Correct 73 ms 10032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -