It is a holiday season, and Koala is decorating his house with cool lights! He owns n lights, all of which flash periodically.

After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters ai and bi. Light with parameters ai and bi will toggle (on to off, or off to on) every ai seconds starting from the bi-th second. In other words, it will toggle at the moments bi, bi+ai, bi+2⋅ai and so on.

You know for each light whether it's initially on or off and its corresponding parameters ai and bi. Koala is wondering what is the maximum number of lights that will ever be on at the same time. So you need to find that out.

Here is a graphic for the first example.

Input

The first line contains a single integer n (1≤n≤100), the number of lights.

The next line contains a string s of n characters. The ii-th character is "1", if the i-th lamp is initially on. Otherwise, i-th character is "0".

The i-th of the following n lines contains two integers ai and bi (1≤ai,bi≤5)  — the parameters of the i-th light.

Output

Print a single integer — the maximum number of lights that will ever be on at the same time.

Examples
input
3
101
3 3
3 2
3 1
output
2
input
4
1111
3 4
5 2
3 1
3 2
output
4
input
6
011100
5 3
5 5
2 4
3 5
4 2
1 5
output
6
Note

For first example, the lamps' states are shown in the picture above. The largest number of simultaneously on lamps is 2 (e.g. at the moment 2).

In the second example, all lights are initially on. So the answer is 4.

解释题意:有n盏灯,1代表开0代表关,初始状态已给出,每盏灯有a和b两个属性,bs之后灯切换一次状态,之后每a秒切换一次状态。求最多同时亮几盏灯。

不难想到我们可以模拟所有的状态而所有状态的周期最多是2*3*4*5+5种。保险起见可以多跑几次

#include <bits/stdc++.h>
using namespace std;
bool a[];
int l[];
int r[];
int c[];
int f[];
int main()
{
int n;
cin>>n;
string str;
cin>>str;
for(int i=;i<str.size();++i)
{
if(str[i]=='')
{
a[i+]=;
}
else
{
a[i+]=;
}
}
for(int i=;i<=n;++i)
{
cin>>l[i]>>r[i];
c[i]=l[i];
}
int mmax=;
int tmp=;
for(int i=;i<=n;++i)
{
if(a[i]==)
{
tmp++;
mmax=max(mmax,tmp);
}
}
for(int k=;k<=;++k)
{
int tmp=;
for(int i=;i<=n;++i)
{
if(a[i]==)
{
tmp++;
mmax=max(mmax,tmp);
}
}
for(int i=;i<=n;++i)
{
if(f[i]==&&r[i]==)
{
c[i]--;
if(c[i]==)
{
c[i]=l[i];
a[i]=!a[i];
}
}
if(r[i]>)
{
r[i]--;
if(r[i]==)
{
a[i]=!a[i];
f[i]=;
}
}
}
}
cout<<mmax;
return ;
}

CF1209B Koala and Lights的更多相关文章

  1. Codeforces Round #584 B. Koala and Lights

    链接: https://codeforces.com/contest/1209/problem/B 题意: It is a holiday season, and Koala is decoratin ...

  2. Codeforces Round #584

    传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...

  3. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...

  4. jQuery可自动播放动画焦点图插件Koala

    Koala是一款简单而实用的jQuery焦点图幻灯片插件,焦点图不仅可以在播放图片的时候让图片有淡入淡出的动画效果,而且图片可以自动播放.该jQuery焦点图的每一张图片都可以设置文字描述,并浮动在图 ...

  5. Sass:初识Sass与Koala工具的使用

    一.下载Koala(找到合适的系统版本)并安装 二.先新建一个css文件夹,并在里面新建一个文本文档(.txt),将其命名为demo.scss 三.打开Koala,将css文件夹拽进来,可以修改一下输 ...

  6. koala预编译工具的使用

    Koala是一个开源的预处理语言图形编译工具,目前已支持Less.Sass.Compass与CoffeeScript. 安装Koala 在Koala官网根据你的系统平台下载对应的版本.Linux系统要 ...

  7. HDOJ 4770 Lights Against Dudely

    状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  8. Ubuntu下安装Koala

    1.下载koala ,官方网址 目前官方链接的到百度云上的包好像有问题,不能安装,这里分享下 https://yunpan.cn/ckAF4L3TR4kKG (提取码:179a) 2.执行 $ sud ...

  9. [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights

    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights 既上一篇分享了中文字幕的摄像机介绍Cameras后,本篇分享一下第2个已完工的 ...

随机推荐

  1. idea中如何将一个普通项目转换为maven项目

    在pom.xml 文件上右键 Add as Maven Project即可.

  2. FTP大量数据(百万级数据)传输尝试

    接上篇<Java FTPClient 大量数据传输的问题(未解决)> 因为数据量过大 FTPClient获取文件列表信息会出现不稳定的问题,找了很多方法都没有解决. 网上找的这一篇文章 h ...

  3. ROS-4 : ROS节点和主题

    依照<ROS-3 : Catkin工作空间和ROS功能包>,创建catkin工作空间,并在起src下创建功能包ros_demo_pkg,依赖项为roscpp.std_msgs.action ...

  4. 17 MySQL的小技巧

    1.正则表达式的使用   ^ 在字符串开始处进行匹配 $ 在字符串末尾处进行匹配 . 匹配任意单个字符,包括换行符 [...]  匹配出括号内的任意字符 [^...]  匹配不出括号内的任意字符 a* ...

  5. Python学习笔记之基础篇(二)python入门

    一.pycharm 的下载与安装: 使用教程:https://www.cnblogs.com/jin-xin/articles/9811379.html 破解的方法:http://xianchang. ...

  6. OO第三次博客作业(第三单元总结)

    (1)梳理JML语言的理论基础.应用工具链情况 Java 建模语言(JML)将注释添加到 Java 代码中,这样我们就可以确定方法所执行的内容,而不必说明它们如何做到这一点.有了 JML,我们就可以描 ...

  7. MongoDB 监控指标

    MongoDB uptime 启动时长 asserts.user 用户的断言数量 asserts.warning 警告的断言数量 connections.current 当前的连接数 大于 650co ...

  8. elasticsearch-java客户端测试

    1.环境准备 (1)添加依赖 <dependency> <groupId>org.elasticsearch.client</groupId> <artifa ...

  9. 使用BP拦截POST型请求包

    1.安装phpstudy并下载wordpress 文件,安装在phpstudy的www目录下 phpstudy下载地址:https://www.xp.cn/download.html wordpres ...

  10. mysql导入导出无权限

    error:The MySQL server is running with the --secure-file-priv option so it cannot execute this state ...