41332023-03-15 11:40:49horvathabelDinamitcpp17Wrong answer 23/503ms4732 KiB
#include <bits/stdc++.h>
#include <queue>
using namespace std;
using ll=long long; 
int main() {
	ll n,m,k;
	cin>>n>>m>>k;
	pair<ll,int> dp[n+1][m+1];
	ll mgs[n+1][m+1];
	for (int i=0; i<n;i++){
		for (int j=0; j<m;j++){
			int x;
			cin>>x;
			mgs[i][j]=x; 
			if (i==0 && j==0) dp[0][0]={x,-1};
			if (i==0 && j!=0) dp[0][j]={dp[0][j-1].first+x,0};
			if (i!=0 && j==0) dp[i][0]={dp[i-1][0].first+x,1};
		}
	}
for (int i=1; i<n;i++){
	for (int j=1; j<m;j++){
		if (dp[i-1][j].first<dp[i][j-1].first){
			dp[i][j]={dp[i-1][j].first+mgs[i][j],1};
		}
		else{
			dp[i][j]={dp[i][j-1].first+mgs[i][j],0};
		}
		
	}
}
priority_queue<ll> q; 
pair<ll, ll> a={n-1,m-1};

	vector<int> z;
while (a.first!=0 or a.second!=0){
	q.push(mgs[a.first][a.second]);
	z.push_back(mgs[a.first][a.second]);
	if (dp[a.first][a.second].second==0) a.second--;
	else a.first--;
}	
q.push(mgs[0][0]);

int ans=dp[n-1][m-1].first;
for (int i=0; i<k;i++){
	int z=q.top(),u=q.top();
	
	q.pop();
	z/=2;
	ans-=u-z;
	q.push(z);
}
cout<<ans; 

}


SubtaskSumTestVerdictTimeMemory
base23/50
1Accepted0/03ms1812 KiB
2Wrong answer0/03ms2220 KiB
3Accepted2/23ms2436 KiB
4Accepted2/23ms2652 KiB
5Accepted3/33ms2800 KiB
6Accepted3/33ms3136 KiB
7Accepted2/23ms3092 KiB
8Accepted3/33ms3232 KiB
9Wrong answer0/23ms3272 KiB
10Accepted2/23ms3528 KiB
11Accepted3/33ms3732 KiB
12Wrong answer0/33ms3856 KiB
13Wrong answer0/23ms3920 KiB
14Accepted3/33ms4132 KiB
15Wrong answer0/23ms4500 KiB
16Wrong answer0/33ms4452 KiB
17Wrong answer0/23ms4452 KiB
18Wrong answer0/33ms4460 KiB
19Wrong answer0/23ms4452 KiB
20Wrong answer0/33ms4732 KiB
21Wrong answer0/23ms4704 KiB
22Wrong answer0/33ms4604 KiB