Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a seconds to swipe from photo to adjacent.

For each photo it is known which orientation is intended for it — horizontal or vertical. Phone is in the vertical orientation and can't be rotated. It takes b second to change orientation of the photo.

Vasya has T seconds to watch photos. He want to watch as many photos as possible. If Vasya opens the photo for the first time, he spends 1 second to notice all details in it. If photo is in the wrong orientation, he spends b seconds on rotating it before watching it. If Vasya has already opened the photo, he just skips it (so he doesn't spend any time for watching it or for changing its orientation). It is not allowed to skip unseen photos.

Help Vasya find the maximum number of photos he is able to watch during T seconds.

Input

The first line of the input contains 4 integers n, a, b, T (1 ≤ n ≤ 5·105, 1 ≤ a, b ≤ 1000, 1 ≤ T ≤ 109) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo.

Second line of the input contains a string of length n containing symbols 'w' and 'h'.

If the i-th position of a string contains 'w', then the photo i should be seen in the horizontal orientation.

If the i-th position of a string contains 'h', then the photo i should be seen in vertical orientation.

Output

Output the only integer, the maximum number of photos Vasya is able to watch during those T seconds.

Examples
Input
4 2 3 10
wwhw
Output
2
Input
5 2 4 13
hhwhh
Output
4
Input
5 2 4 1000
hhwhh
Output
5
Input
3 1 100 10
whw
Output
0
Note

In the first sample test you can rotate the first photo (3 seconds), watch the first photo (1 seconds), move left (2 second), rotate fourth photo (3 seconds), watch fourth photo (1 second). The whole process takes exactly 10 seconds.

Note that in the last sample test the time is not enough even to watch the first photo, also you can't skip it.

题意:给n张图片循环可看,每张图片的朝向为横(w)|竖(v),但是手机是竖直放置的。开始时打开的是第0张图片,如果一张图片为w放置就需先花b秒边把该张图片变成v朝向,从一张图片到下一张图片手机的反应时间为a秒,每观察一张图片需要1秒钟。不能直接跳过没看的图片,但是重新刷到看过的图片时,所花的时间只是手机的反应时间,不复看;问在t秒内能看的最多图片的数目为多少?

思路:预处理"看"每张图片所需的时间,即包括是否翻转;把总时间记录在sum中,并且由于可以从第0张开始顺序看和逆序看,直接弄成2*n的空间,把n当成原来的第0张,这样[l,r)就是所看的图片区间。线性处理[l,r]之间的时间即可;时间复杂度为O(n)

#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
ll i,j,k,n,a,b,t,ans,cnt,sum;
const int N = 1e6+;
int w[N];
char s[N];
int main()
{
scanf("%d%d%d%d%s",&n,&a,&b,&t,s);
for(i = ;i < n;i++){
if(s[i] == 'w') w[i] = w[i+n] = b+;
else w[i] = w[i+n] = ;
sum += w[i];
}
sum -= w[];
ll l = ,r = n; // 以n = 0为起点,向左到l,向右到 r-1
while(l <= n && r < n+n){ // l = n表示只是顺序看图片
sum += w[r++];
while(r-l > n || sum+(r-l-+min(r--n,n-l))*a > t)
sum -= w[l++];
ans = max(ans,r-l);
}
cout<<ans;
}

Codeforces Round #345 (Div. 1) B. Image Preview的更多相关文章

  1. Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分

    D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

  4. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  5. Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集

    题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...

  6. Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集

    E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...

  7. Codeforces Round #345 (Div. 1) D. Zip-line 上升子序列 离线 离散化 线段树

    D. Zip-line 题目连接: http://www.codeforces.com/contest/650/problem/D Description Vasya has decided to b ...

  8. Codeforces Round #345 (Div. 2) E. Table Compression 并查集

    E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...

  9. Codeforces Round #345 (Div. 1) A - Watchmen 容斥

    C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...

随机推荐

  1. Android 开发中的屏幕适配技术详解

    本文主要介绍Android开发中比较头疼繁琐的一个问题-屏幕适配问题.主要从适配原因.基本核心概念.适配方法等方面介详细 介绍从而是的深入或者进一步对Android屏幕适配技术的掌握和理解. 真题园网 ...

  2. opencv中的基本拼接

    普通版的图像拼接,事实上非常简单并且效果不很差. 实现方式: 新建工程: 去opencv里面[f:\opencv249\opencv\sources\samples\cpp]把stitching.cp ...

  3. CentOS 简单命令

    一.启动级别 Linux系统设置系统启动模式的方式可以修改(必须要以root身份登录才能修改).修改系统启动模式的配置文件是   /etc/inittab. 我们在切换到root用户后,然后 vi / ...

  4. LINUX-----管道流及重定向

    1.管道流 在linux中  | 符号代表管道流 用法:command1 | command2 第一个命令的标准输出将作为第二个命令的标准输入 例:cat a.txt | grep "abc ...

  5. Java读取一个文件并打印到控制台上

    package test9; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundExcept ...

  6. RavenScheme简介

    RavenScheme简介 RavenScheme使用了一个运行『读入-求值-打印』循环的解释器.该解释器从标准输入反复的读入表达式,对得到的表达式求值,然后打印出结果. 如果用户键入: [加 1 2 ...

  7. ACM——Digital Roots

    http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028 Digital Roots 时间 ...

  8. dagger和butterknife使用冲突

    两者会冲突的主要原因是因为两者都有:javax.annotation.processing.Processor 于是在build.gradle中添加如下配置即可: // 注释冲突 packagingO ...

  9. [转载]sql server 等待类型

    下表列出各任务所遇到的等待类型. 等待类型 说明 ASYNC_DISKPOOL_LOCK 当尝试同步并行的线程(执行创建或初始化文件等任务)时出现. ASYNC_IO_COMPLETION 当某任务正 ...

  10. Git版本管理:Windows下Git配置与使用指南 Gitlab

    简要介绍:Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理. 一.安装 软件:msysGit-fullinstall-1.8.1.2 打开之后设置安装路径,默认为 ...