CodeForces - 734C (thinking)

Keywords: iOS

Every time I think about why I can't think of a solution. Why people's code is several lines.. (or write too little code by yourself QAQ)

When I write this question, I still wonder if I want to search or use greed. When I see the big guy's code, I realize that thinking is really strong.

 

Idea: first find the directly generated one. And then we use violence (combined with dichotomy) to solve it.

 

Code:

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
const int MAX_N=1000000+50;
const int INF=0x3f3f3f3f;
const double EPS = 1e-10;
ll mod = 1e9+7;

ll a[MAX_N],b[MAX_N],c[MAX_N],d[MAX_N]; 

int main(){
	ll n,m,k,x,s;
	cin>>n>>m>>k>>x>>s;
	for(int i = 0 ; i < m; i++) cin>>a[i];
	for(int i = 0 ; i < m; i++) cin>>b[i];
	for(int i = 1 ; i <= k; i++) cin>>c[i];
	for(int i = 1 ; i <= k; i++) cin>>d[i];
	ll ans = (n - c[upper_bound(d+1,d+k+1,s) - d - 1]) * x;
	for(int i = 0; i < m; i++){
		if(b[i] > s) continue;
		ans = min(ans, (n - c[upper_bound(d+1,d+k+1,s-b[i]) - d - 1]) * a[i]);
	}
	cout<<ans<<endl;
 	return 0;
}

/*
                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
*/

 

Posted by rblais666 on Mon, 06 Jan 2020 11:20:11 -0800